'>Hextor_6.BSx '============================================================== '{$stamp BS2Sx} '============================================================== 'Introduction to controlling Hextor using the infra-red 'communication link (IR-link) and or the LCD pendant. 'To use the IR-link the receiver must first be trained to 'recognise the codes from your handset. 'See the 'Hextor-Manual, Documents, IR-Receiver'. ' 'Note how the srmlQT settings remain in force until re-written. ' 'New '--- ' 'Constant: 'Variable: btn now set in subroutine btns 'Subroutine:btns rewritten 'LCD text: messages and names altered '============================================================== 'LCD commands. 'In Hextor_5LCD the various commands introduced to control the 'LCD were given names such as LCDcls, however this makes the 'program very wordy. Now you have an idea of how to write text 'to the LCD and read the state of the buttons on the LCD 'pendant we will use the following command codes themselves. 'For more detailed information see the ILM-216 User Manual. 'Function ASCII '-------- ----- 'Null 0 'Cursor home 1 'Hide cursor 4 'Show underline cursor 5 'Show blinking-block cursor 6 'Bell (not implemented with Hextor LCD) 7 'Backspace 8 'Horezontal tab (4 columns) 9 'Smart linefeed (cursor down one line) 10 'Vertical tab (cursor up one line) 11 'Formfeed (clear screen) 12 'Carriage return 13 'Backlight on 14 'Backlight off 15 'Accept cursor position entry 16 ' 64 is the start of the first line ' 80 is the start of the second line 'Format right aligned text 18 'Escape (ESC; start multipart instruction) 27 '==========LCD messages - finish each message with Null ======= lcd1 data 1,"Wiggles 1 - 3 1 2 3 - ",0 lcdb1 data 12," Wiggle 1",0 lcdb2 data 12," Wiggle 2",0 lcdb3 data 12," Wiggle 3",0 '============================================================== BOStx con 0 'pin serial to BOS processor BOSrx con 1 'pin serial from BOS processor epower con 2 'pin high turns on power to electronics BOSbusy var in4 'pin BOS processor busy => high irrx con 5 'pin infra red comms in, i96n lcdtx con 6 'pin to send to LCD lcdrx con 7 'pin to receive from LCD Rled con 8 'pin high turns on right green led Lled con 9 'pin high turns on left red led i96n con 16624 '9600 baud, 8 bit, no parity, inverted poweruptime con 1500 'pause before powering up electronics BOScmnd var byte 'byte to send to BOS processor Sptr var byte 'pointer to DATA sequence string arg1 var byte 'command argument irin var byte 'infra-red command lcdbtns var byte 'button states are in lower nibble btn1state var lcdbtns.bit0 btn2state var lcdbtns.bit1 btn3state var lcdbtns.bit2 btn4state var lcdbtns.bit3 btn var nib '0 - 4 button currently pressed lcdmsg var word 'pointer to current char in text lcdchar var byte 'character to send to LCD 'during downloading the power to the electronics is turned off, 'if it is turned back on again too soon the electronics, 'especially the ultrasonics do not power up properly, 'so wait poweruptime before turning power on. init: output Rled output Lled high Rled high Lled pause poweruptime high epower 'turn on electronics init1:gosub irget pause 100 'no point in listening too often if irin<>0 then init1 'wait for ir to initialise debug cls pause 1000 'give time for lcd to get ready 'IR circuit sometimes starts up with a false key of 2 gosub irget pause 100 'no point in listening too often if irin<>0 then init1 'wait for false key to end 'Sequence in DATA statments '--------------------------- wiggle1 DATA "s",4,"r",170,"QUDFBCRLOBPMz" wiggle2 DATA "s",0,"r",200,"TUFFBBz" wiggle3 DATA "TUFRRLLBz" 'Program start '------------- start:toggle Rled pause 50 lcdmsg =lcd1: gosub lcd 'write some text gosub btns 'read button state gosub irget if irin=1 or btn=1 then wig1 'irkey 1 or button 1 if irin=2 or btn=2 then wig2 'irkey 2 or button 2 if irin=3 or btn=3 then wig3 'irkey 3 or button 3 toggle Lled goto start '------------- leaves -------------------------- wig1: Sptr =wiggle1 lcdmsg =lcdb1: gosub lcd gosub dosequence goto start 'check ir wig2: Sptr =wiggle2 lcdmsg =lcdb2: gosub lcd gosub dosequence goto start 'check ir wig3: Sptr =wiggle3 lcdmsg =lcdb3: gosub lcd gosub dosequence goto start 'check ir '------------- subroutines --------------------- lcd: read lcdmsg,lcdchar if lcdchar=0 then lcdret 'if 0 then end of msg serout lcdtx,i96n,[lcdchar] lcdmsg =lcdmsg +1 'point to next character goto lcd lcdret:return '-------------------- btns: lcdbtns =0 'set a default value serout lcdtx,i96n,[27,"K0"] 'ask LCD for button status serin lcdrx,i96n,200,nolcd,[lcdbtns] 'get byte nolcd:btn =NCD lcdbtns.lownib '0 - 4 return '----------------------- nobtns:lcdbtns =0 'wait until no buttons are pressed nbtn: serout lcdtx,i96n,[27,"K0"] 'ask LCD for button status serin lcdrx,i96n,200,nolcd,[lcdbtns] 'get byte if lcdbtns.lownib<>0 then nbtn return '-------------------- irget:'listen to InfraRed co-processor irin =0 'set to idle value serin irrx,i96n,100,noir,[irin] 'valid 0 - 8 irin =irin & $F 'mask high nibble timing data noir: return '-------------------- dosequence: 'loop round until BCbyte="z" read Sptr,BOScmnd if BOScmnd="z" then doneR arg1 =255 lookdown BOScmnd,["srml"],arg1 if arg1=255 then t1 'BOScmnd not srm or l, jump to t1 Sptr =Sptr+1 'point to argument read Sptr,arg1 'read it gosub tellBOS1d 'send them goto nxt 'go onto next operation t1: gosub tellBOS nxt: Sptr =Sptr+1 goto dosequence doneR:return '-------------------- tellBOS: pause 10 'give the BOS time to go into receive mode if BOSbusy=1 then tellBOS 'wait until BOS not busy serout BOStx,i96n,[BOScmnd] return '-------------------- tellBOS1d: 'send command plus one argument in decimal pause 10 'give the BOS time to go into receive mode if BOSbusy=1 then tellBOS1d 'wait until BOS not busy serout BOStx,i96n,50,[BOScmnd,dec arg1,cr] '50 pace time return '------------------------ end program -------------------------