SYMBOL RS = 2 ; 0 = Command 1 = Data SYMBOL E = 3 ; 0 = Idle 1 = Active SYMBOL DB4 = 4 ; LCD Data Line 4 SYMBOL DB5 = 5 ; LCD Data Line 5 SYMBOL DB6 = 6 ; LCD Data Line 6 SYMBOL DB7 = 7 ; LCD Data Line 7 SYMBOL RSCMDmask = %00000000 ; Select Command register SYMBOL RSDATmask = %00000100 ; Select Data register SYMBOL get = b11 SYMBOL byte1 = b12 SYMBOL rsbit = b13 SYMBOL counter = b3 SYMBOL ledPin = 0 SYMBOL flash_count = 4 SYMBOL hundreds = b5 SYMBOL tens = b6 SYMBOL units = b7 SYMBOL statusByte = b8 'setup the LCD GOSUB InitialiseLcd 'flash LED GOSUB flashLED main: 'wait for incoming tank data serin 7,N2400,("ABC"),b1,b2 'flash LED GOSUB flashLED 'send tank data to serial cable 'sertxd ("tank,",#b1,",",#b2,cr,lf) 'update LCD with tank level and cell voltage GOSUB UpdateTankLevel GOSUB UpdateCellLevel 'flash LED GOSUB flashLED goto main flashLED: for counter = 1 to flash_count high ledPin pause 100 low ledPin pause 100 next counter return InitialiseLcd: ' Nibble commands - To initialise 4-bit mode EEPROM 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit EEPROM 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit ' Byte commands - To configure the LCD EEPROM 2,( $28 ) ; %00101000 %001LNF00 Display Format EEPROM 3,( $0C ) ; %00001100 %00001DCB Display On EEPROM 4,( $06 ) ; %00000110 %000001IS Cursor Move ; L : 0 = 4-bit Mode 1 = 8-bit Mode ; N : 0 = 1 Line 1 = 2 Lines ; F : 0 = 5x7 Pixels 1 = N/A ; D : 0 = Display Off 1 = Display On ; C : 0 = Cursor Off 1 = Cursor On ; B : 0 = Cursor Steady 1 = Cursor Flash ; I : 0 = Dec Cursor 1 = Inc Cursor ; S : 0 = Cursor Move 1 = Display Shift EEPROM 5,( $01 ) ; Clear Screen FOR get = 0 TO 5 READ get,byte1 GOSUB SendInitCmdByte NEXT DisplayTopLine: EEPROM 6,("Tank level: ---%") FOR get = 6 TO 21 READ get,byte1 GOSUB SendDataByte NEXT MoveCursorToStartOfSecondLine: byte1 = $C0 GOSUB SendCmdByte DisplayBottomLine: EEPROM 22,("Cell: -.--V") FOR get = 22 TO 32 READ get,byte1 GOSUB SendDataByte NEXT return SendInitCmdByte: PAUSE 15 ; Delay 15mS SendCmdByte: rsbit = RSCMDmask ; Send to Command register SendDataByte: pins = byte1 & %11110000 | rsbit ; Put MSB out first PULSOUT E,1 ; Give a 10uS pulse on E pins = byte1 * %00010000 | rsbit ; Put LSB out second PULSOUT E,1 ; Give a 10uS pulse on E rsbit = RSDATmask ; Send to Data register next RETURN UpdateTankLevel: byte1 = $8C GOSUB SendCmdByte bintoascii b1,hundreds,tens,units if hundreds = "0" then hundreds = " " endif if hundreds = "0" AND tens = "0" then tens = " " endif byte1 = hundreds GOSUB SendDataByte byte1 = tens GOSUB SendDataByte byte1 = units GOSUB SendDataByte return UpdateCellLevel: byte1 = $C6 GOSUB SendCmdByte bintoascii b2,hundreds,tens,units byte1 = hundreds GOSUB SendDataByte byte1 = "." 'decimal point GOSUB SendDataByte byte1 = tens GOSUB SendDataByte byte1 = units GOSUB SendDataByte return