Writing Word value to LCD using i2c

Jeremy Leach

Senior Member
I'm not claiming this is the best code, but it seems to work and maybe helpful

Symbol True = 1
Symbol False = 0
Symbol TempWord = w3
Symbol DigitIndex = b0
Symbol ResultRemainder = w4
Symbol ResultWhole = w5
Symbol Divisor = w6
Symbol DisplayStarted = b1

DisplayWordValue:
'Displays unsigned TempWord value on LCD.
'Note highest word value is 65535, ie 5 digits

Divisor = 10000
DisplayStarted = False
For DigitIndex = 1 to 5
ResultWhole = TempWord / Divisor
ResultRemainder = TempWord % Divisor
If ResultWhole = 0 and DisplayStarted = False and DigitIndex < 5 then DisplayWordValue_1

'Display the digit on the LCD
DisplayStarted = True
ResultWhole = ResultWhole +"0" 'Convert to ASCII
Writei2C 0,(ResultWhole,255)
Pause 10

DisplayWordValue_1:
TempWord = ResultRemainder
Divisor = Divisor / 10
Next
Return

Edited by - Jeremy Leach on 4/12/2005 1:16:24 PM
 
Top