'>Hextor_7.BSx '============================================================== '{$stamp BS2Sx} '============================================================== 'Re-oganisation of sequences so settings s,r,m,l, can be 'selected by key commands without running a sequence as well. ' 'lcdmenu written to read the buttons and write to the lcd ' 'New '--- 'Required knowledge: ' 'Constant: lcdoptions 'Variable: btnc,mendo 'Subroutine:lcdmenu 'LCD text: messages and names altered '============================================================== 'Experiment with the s,r,m,l commands '============================================================== 'LCD commands. '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 ======= dbtxt data 12,4,16,80," -- < > ok ",0 dbusy data 16,76,"busy",0 dm0 data 1,"OPTIONS ",0 dm1 data 1,"Wiggle 1 ",0 dm2 data 1,"Wiggle 2 ",0 dm3 data 1,"Wiggle 3 ",0 dm4 data 1,"Setting 1 ",0 dm5 data 1,"Setting 2 ",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 lcdbtns.lownib '0 - 4 current button state oldbtn var nib '0 - 4 last button state lcdmsg var word 'pointer to current char in text lcdchar var byte 'character to send to LCD btnc var nib 'current BuTtoN Choice from menu mendo var nib 'selection chosen by OK lcdoptions con 5 'number of menu options '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 lcdmsg =dbtxt :gosub lcd 'write button text 'Sequences in DATA statments '--------------------------- wiggle1 DATA "UDFBCRLOBPMz" wiggle2 DATA "UFFBBz" wiggle3 DATA "UFRRLLBz" setting1 DATA "Qs",4,"r",170,"z" setting2 DATA "Ts",0,"r",200,"z" 'feet drag if not "T" 'Program start '------------- start:toggle Rled pause 50 mendo =0 gosub lcdmenu 'returns menndo case: if mendo=1 then wig1 'key/mendo 1 if mendo=2 then wig2 'key/mendo 2 if mendo=3 then wig3 'key/mendo 3 if mendo=4 then set1 'key/mendo 4 if mendo=5 then set2 'key/mendo 5 toggle Lled pause 50 goto start '------------- leaves -------------------------- wig1: Sptr =wiggle1 lcdmsg =dm1 :gosub lcd lcdmsg =dbusy :gosub lcd gosub dosequence goto start wig2: Sptr =wiggle2 lcdmsg =dm2 :gosub lcd lcdmsg =dbusy :gosub lcd gosub dosequence goto start wig3: Sptr =wiggle3 lcdmsg =dm3 :gosub lcd lcdmsg =dbusy :gosub lcd gosub dosequence goto start set1: Sptr =setting1 lcdmsg =dm4 :gosub lcd lcdmsg =dbusy :gosub lcd gosub dosequence goto start set2: Sptr =setting2 lcdmsg =dm5 :gosub lcd lcdmsg =dbusy :gosub lcd gosub dosequence goto start '------------- subroutines --------------------- lcdmenu: lcdit:lookup btnc,[dm0,dm1,dm2,dm3,dm4,dm5],lcdmsg gosub lcd lcdb: gosub irget if irin=0 then mbtns mendo =irin return 'with ir cmdn mbtns:gosub btns if btn=oldbtn then lcdb oldbtn =btn if btn=2 then lcd2 if btn=3 then lcd3 if btn=4 then lcd4 goto lcdb lcd2: btnc =1 +btnc -1 min 1 -1 :goto lcdit '+1 -1 => don't go through 0 lcd3: btnc =btnc +1 max lcdoptions :goto lcdit lcd4: mendo =btnc lcdmsg =dbusy :gosub lcd gosub nobtns return '-------------------- 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 -------------------------