'>Hextor_5LCD.BSx '============================================================== 'Milford Instruments http://www.milinst.com 'Hextor Design, Bug Commander - Behavioural Operating System 'and the Behavioural Controller programs by David Buckley '================================================================ '{$stamp BS2Sx} '============================================================== 'Debug program for testing LCD and buttons on the LCD Pendant ' 'New '--- 'Required knowledge: serin, &, serout..[dec..] ' debug (not vital but it helps) ' 'Constant: lcdtx,lcdrx,ESC,LCDhome,LCDlighton,LCDlightoff ' LCDpsmode,LCDline1,LCDline2,pressed 'Variable: lcdbtns,btn1state - btn4state 'Subroutine:lcd btns nobtns '============================================================== epower CON 2 'pin high turns on power to electronics 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 ESC CON 27 'ESCape value for LCD LCDhome CON 1 'value to home LCD cursor LCDcls CON 12 'value to clear LCD screen LCDlighton CON 14 'cmnd value to turn on LCD backlight LCDlightoff CON 15 'cmnd value to turn off LCD backlight LCDposmde CON 16 'cmnd val for position mode LCDline1 CON 64 'address of start of line 1 LCDline2 CON 80 'address of start of line 2 pressed CON 1 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 'during downloading the power to the electronics is turned off, 'if it is turned back on again too soon the electronics do not 'power up properly,so wait 1 second before turning power on. init: OUTPUT Rled OUTPUT Lled HIGH Rled HIGH Lled PAUSE poweruptime HIGH epower 'turn on electronics DEBUG CLS PAUSE 1000 'give time for lcd to get ready SEROUT lcdtx,i96n,[LCDcls,"LCD example"] PAUSE 1000 'give time to read message 'Program start '------------- start: TOGGLE Rled PAUSE 100 GOSUB lcd 'write some text butn: GOSUB btns 'read button state IF btn1state=pressed THEN lcdbtn1 'if button 1 IF btn2state=pressed THEN lcdbtn2 'if button 2 IF btn3state=pressed THEN lcdbtn3 'if button 3 IF btn4state=pressed THEN lcdbtn4 'if button 4 GOTO start '------------- leaves -------------------------- lcdbtn1: 'example of turning on backlight SEROUT lcdtx,i96n,[LCDhome] SEROUT lcdtx,i96n,[LCDlighton,"Btn 1 - light on"] GOSUB nobtns GOTO butn '----------------------- lcdbtn2: 'example of turning off backlight SEROUT lcdtx,i96n,[LCDhome] SEROUT lcdtx,i96n,[LCDlightoff,"Btn 2 light off"] GOSUB nobtns GOTO butn '----------------------- lcdbtn3: SEROUT lcdtx,i96n,[LCDhome," Button 3 "] GOSUB nobtns GOTO butn '----------------------- lcdbtn4: SEROUT lcdtx,i96n,[LCDhome," Button 4 "] GOSUB nobtns GOTO butn '------------- subroutines --------------------- lcd: SEROUT lcdtx,i96n,[LCDposmde,LCDline1," No button "] SEROUT lcdtx,i96n,[LCDposmde,LCDline2," Press a button "] RETURN '----------------------- btns: SEROUT lcdtx,i96n,[ESC,"K0"] 'ask LCD for button status SERIN lcdrx,i96n,200,nolcd,[lcdbtns] 'get byte nolcd: 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 '------------------------ end program -------------------------