symbol counter = w0
symbol subcounter = b2
symbol fontlookup = b3
symbol pixels = b4
symbol displaybank = b5
symbol Volt = w4
symbol SOC = w5
symbol timetillemptymins = w6
Symbol Current = w10
symbol bTmp = w7
symbol bTemp = w8
Pause 30
serout C.4,N2400,(254,1) ; Clear serial display
Pause 30
; save Font codes in EEPROM
eeprom 0,(124,130,130,130,124) ; 0 (ASCII 48)
eeprom 5,(136,132,254,128,128) ; 1
eeprom 10,(196,162,162,146,140) ; 2
eeprom 15,(68,130,146,146,108) ; 3
eeprom 20,(48,40,36,254,32) ; 4
eeprom 25,(110,138,138,138,114) ; 5
eeprom 30,(124,146,146,146,100) ; 6
eeprom 35,(2,2,2,2,254) ; 7
eeprom 40,(108,146,146,146,108) ; 8
eeprom 45,(30,18,18,18,254) ; 9 (ASCII 57)
eeprom 50,(254,18,18,18,254) ; A (ASCII 65)
eeprom 55,(254,146,146,146,108) ; B
eeprom 60,(254,130,130,130,130) ; C
eeprom 65,(254,130,130,68,56) ; D
eeprom 70,(254,146,146,146,130) ; E
eeprom 75,(254,18,18,18,2) ; F
eeprom 80,(254,130,130,146,242) ; G
eeprom 85,(254,16,16,16,254) ; H
eeprom 90,(130,130,254,130,130) ; I
eeprom 95,(226,130,254,2,2) ; J
eeprom 100,(254,16,40,68,130) ; K
eeprom 105,(254,128,128,128,128) ; L
eeprom 110,(254,2,254,2,254) ; M
eeprom 115,(254,4,56,64,254) ; N
eeprom 120,(254,130,130,130,254) ; O
eeprom 125,(254,18,18,18,12) ; P
eeprom 130,(124,130,162,66,188) ; Q
eeprom 135,(254,18,50,82,140) ; R
eeprom 140,(222,146,146,146,246) ; S
eeprom 145,(2,2,254,2,2) ; T
eeprom 150,(126,128,128,128,126) ; U
eeprom 155,(30,96,128,96,30) ; V
eeprom 160,(254,128,254,128,254) ; W
eeprom 165,(198,40,16,40,198) ; X
eeprom 170,(6,8,240,8,6) ; Y
eeprom 175, (68,32,16,8,68) ; Z (ASCII 90)
eeprom 180,(194,162,146,138,134) ; %
initialise:
; initialise i2c for display (ID 0x78) and then send power up instructions
hi2csetup i2cmaster,$78,i2cfast,i2cbyte
hi2cout 0x80,(0xAE,0x00,0x00,0xB0,0x20,0x00,0xD5,0x80,0xA8,0x1F,0xD3,0x00,0x8D, _
0x14,0xA1,0x00,0xC8,0xDA,0x02,0x81,0xCF,0xD9,0xF1, 0xDB,0x30,0xA4,0xA6)
gosub sendtodisplay ; send 4 blank lines to clear display
let displaybank = 0 ; flag rows 0-3 for display
hi2cout 0x80,(0xAF) ; turn display on
serout C.0,N2400,(254,1) ; Clear serial display
main:
i2cslave 0x16, i2cslow, i2cbyte
readi2c 0x09,(b8,b9) ; Read volt from eeprom
readi2c 0x0d,(b10,b11) ; Read SOC from eeprom
readi2c 0x11,(b12,b13) ; Read time till empty mins from eeprom
readi2c 0x0b,(b24,b25) ; Read current from eeprom
;NEW CODE ATTEMPT
b24 = -10
if b24 >=$80 then write w10, $f0, $aa, $07, $05, b24, $ff, $55
else write w10, $f0, $aa, $07, $05, b24,$00,$55
end if
debug
hi2csetup i2cmaster,$78,i2cfast,i2cbyte;
; Insert your programme code here and then poke 28-91 with message to be displayed
;data to send to display (4 * 16)
poke 28,"T","i","m","e"," ","l","e","f","t"," "
bTmp = timetillemptymins / 10000 // 10 + "0" : Poke 38, bTmp
bTmp = timetillemptymins / 1000 // 10 + "0" : Poke 39, bTmp
bTmp = timetillemptymins / 100 // 10 + "0" : Poke 40, bTmp
bTmp = timetillemptymins / 10 // 10 + "0" : Poke 41, bTmp
bTmp = timetillemptymins // 10 + "0" : Poke 42, bTmp
poke 43," "
poke 44,"V","O","L","T"," "," "," "," "," " ," "
bTmp = Volt / 10000 // 10 + "0" : Poke 54, bTmp;
bTmp = Volt / 1000 // 10 + "0" : Poke 55, bTmp
bTmp = Volt / 100 // 10 + "0" : Poke 56, bTmp
bTmp = Volt / 10 // 10 + "0" : Poke 57, bTmp
bTmp = Volt // 10 + "0" : Poke 58, bTmp
poke 59," "," "
poke 60,"s","o","c"," "," "," "," "," "," "," "
bTmp = SOC / 1000 // 10 + "0" : Poke 70, bTmp
bTmp = SOC / 100 // 10 + "0" : Poke 71, bTmp
bTmp = SOC / 10 // 10 + "0" : Poke 72, bTmp
bTmp = SOC // 10 + "0" : Poke 73, bTmp
poke 74,"z"," "
poke 76,"C","U","R","R","E","N","T"," "," "," "
bTmp = Current / 1000 // 10 + "0" : Poke 86, bTmp
bTmp = Current / 100 // 10 + "0" : Poke 87, bTmp
bTmp = Current / 10 // 10 + "0" : Poke 88, bTmp
bTmp = Current // 10 + "0" : Poke 89, bTmp
poke 90," "," "
displaybank = 1 - displaybank ; toggle lines to display
gosub sendtodisplay ; load message to display memory and point display at it
; Insert any further code you require here
;serout C.0,N2400,(254,140) ; Clear serial display
Pause 30
serout c.4,N2400,(254,128) ; move to start of first line
serout c.4,N2400,("Time left ",#w6)
serout c.4,N2400,(254,192) ; move to start of second line
serout c.4,N2400,("Charge ",#SOC,"%")
goto main
sendtodisplay: ; sends characters in memory locations 28-91 to the display
for counter = 28 to 91
PEEK counter, fontlookup ; load character to output
select case fontlookup
case 48 to 57 ; 0-9
fontlookup = fontlookup - 48 * 5
case 65 to 90 ; A-Z
fontlookup = fontlookup -65 * 5 + 50
case 97 to 123 ; a-z output as A-Z
fontlookup = fontlookup - 97 * 5 + 50
else
fontlookup = 244 ; all other characters will display a blank
endselect
hi2cout 0x40,(0) ; one blank column
for subcounter = 0 to 4
read fontlookup, pixels
hi2cout 0x40,(pixels) ; followed by 5 columns per character
fontlookup = fontlookup + 1
next subcounter
hi2cout 0x40,(0,0) ; two blank columns
next counter ; this completes the 8x8 character output
If displaybank = 0 then
hi2cout 0x80,(0x40) ; point display to lines 0-3 of display memory
else hi2cout 0x80,(0x60) ; point display to lines 4-7 of display memory
Endif
return