'>Hextor_5LCD2.BSx '============================================================== '{$stamp BS2Sx} '============================================================== 'Debug program for testing LCD and buttons on the LCD Pendant. ' 'Introduces a method of storing LCD text in DATA and the use of 'ENCode on the button states to get a button number, so if 'required a BRANCH can be made depending on the button pressed. ' 'New '--- 'Required knowledge: serin, &, serout..[dec..] ' debug (not vital but it helps) ' 'Constant: 'Variable: btn,lcdmsg,lcdchar 'Subroutine:btns rewritten,lcd rewritten '============================================================== '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 12,"LCD example",0 lcd2 data 16,64," No button ",16,80," Press a button",0 lcdb1 data 1,"Btn 1 - light on",0 lcdb2 data 1,"Btn 2 light off",0 lcdb3 data 1," Button 3 ",0 lcdb4 data 1," Button 4 ",0 '============================================================== 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 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 LCDposmode 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 lcdbtns var byte 'button states are in lower nibble btn var nib '1 - 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 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 lcdmsg =lcd1: gosub lcd 'write some text pause 1000 'give time to read message 'Program start '------------- start:toggle Rled pause 100 lcdmsg =lcd2: gosub lcd 'write some text butn: gosub btns 'read button state btn =NCD lcdbtns.lownib '0 - 4 if btn=0 then start if btn=0 then start '0 is idle value if btn=1 then lcdbtn1 'button 1 if btn=2 then lcdbtn2 'button 2 if btn=3 then lcdbtn3 'button 3 if btn=4 then lcdbtn4 'button 3 goto butn '------------- leaves -------------------------- lcdbtn1: 'example of turning on backlight lcdmsg =lcdb1: gosub lcd serout lcdtx,i96n,[LCDlighton] gosub nobtns goto butn '----------------------- lcdbtn2: 'example of turning off backlight lcdmsg =lcdb2: gosub lcd serout lcdtx,i96n,[LCDlightoff] goto butn '----------------------- lcdbtn3: serout lcdtx,i96n,[LCDlightoff] lcdmsg =lcdb3: gosub lcd gosub nobtns goto butn '----------------------- lcdbtn4: serout lcdtx,i96n,[LCDlightoff] lcdmsg =lcdb4: gosub lcd gosub nobtns goto butn '------------- 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,[ESC,"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 '------------------------ end program -------------------------