pleiser
Senior Member
As mentioned previously I am working on a PICAXE laptop,it occasionaly spontaniously freezes at various point in the program (program requests 2 keys from picaxe 28X2 i2c slave keyboard monitor (similar to setup with diy laptop here), saves to alfat (via i2c) and displays info from alfat (always !00 (command sucessful) and goes to menu). at a random point the program appears to stop (according to both OLED and toggling debug LED the relevant parts of the program are:
The keyboard leds flash even after the freeze, so I dont think the keyboard monitering chip is the problem, so what is the error in my code??
~thanks, Patrick
p.s. for completeness here is the keyboard moniter code:
Code:
'picaxe laptop demo program slot 0
#picaxe 28x2
#slot 0
'i2c constants
symbol alfat=%10100100
symbol keyboard=%01010100
'system variables
symbol screenlevel=bit0
symbol loopcount=b11
'keyboard variables
symbol keycheck = b4
symbol keyraw =b5
symbol keyascii = b6
symbol keynum = b7
'wordedit variables
symbol cursorrow = b8
symbol cursorcol = b9
symbol cursorpos = b10
'game variables
'symbol guesscount = b11
'symbol hitcount = b0
'symbol gamerandom = b12
'symbol gamerandom2 =b13
'symbol gamerandom3 =b14
'symbol gamerandom4 =b15
'symbol gamerandom5 =b16
'symbol gamerandom6 =b17
'symbol gamerandom7 =b18
'symbol gamerandom8 =b19
hi2csetup i2cmaster,alfat,i2cfast,i2cbyte
'pause 200
hi2cout ("I M:",lf)
setup:
hi2cin (b12)
if b12=255 then setup2
if b12 <> "!" then setup
hi2cin (b12,b12,b12)
hi2cout ("I M:",lf)
setup2:
pause 530
serout C.1, N2400, (254,1)'clear display
pause 40
serout C.1, N2400, (254,128)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
menu:
main:
serout C.1,N2400, (254,128)
serout C.1, N2400, (254,1)
pause 30
serout C.1,N2400, ("1 Utilities")
serout C.1,N2400,(254,192,"2 Tests")
serout C.1,N2400,(254,148,"3 SD card")
'serout C.1,N2400,(254,148,"3 games")
serout C.1,N2400, (254,212,"4 other")
'serout C.1,N2400,(254,212,"4 calculator")
gosub getakey
branch keynum, (menu,utilitymenu, testmenu,gamemenu,othermenu)
goto menu
'....
gamemenu: 'sd card menu
'run 1
serout C.1,N2400, (254,128)
serout C.1, N2400, (254,1)
serout C.1, N2400, ("1 read sdcard")
serout C.1, N2400, (254,192,"2 reader number")
serout C.1, N2400, (254,148,"3 add to visitor log")
serout C.1, N2400, (254,212,"4 view visitor log")
'serout C.1,N2400, ("no games, press esc")
'serout C.1,N2400,(254,192,"- subtraction")
'serout C.1,N2400,(254,148,"* multiplication")
'serout C.1,N2400,(254,212,"/ division")
gosub getakey
branch keynum, (menu,sdreadsetup,sdtestsetup,visitorlogappend)
if keyraw =118 or keyraw=108 then menu
goto gamemenu
visitorlogappend:
serout C.1, N2400,(254,1)
pause 30
do
pause 100
loop until pinC.0=0
hi2cout [alfat],("O 1A>M:",92,"visitor log.txt",lf)
hi2cin (b12,b12,b12,b12)
serout C.1, N2400, (254,128,"initials?")
gosub getakey
serout C.1, N2400,(254,148,keyascii,".")
b13=keyascii
gosub getakey
serout C.1, N2400,(keyascii,".")
do
pause 100
loop until pinC.0=0
hi2cout ("W 1>5",lf)
pause 10
for loopcount=0 to 19
hi2cin (b12)
serout C.1, N2400, (b12)
inc cursorrow
gosub position
next loopcount
pause 1000
hi2cout (b13,".",keyascii,". ")
serout C.1,N2400, (254,192)
pause 1000
hi2cout ("C 1",lf)
pause 100
hi2cout ("C 1",lf)
for loopcount=0 to 19
hi2cin (b12)
serout C.1, N2400, (b12)
next loopcount
serout C.1, N2400, ("complete")
pause 1000
toggle b.7
goto menu
'...
getakey: 'key detecting subroutine
'hi2csetup i2cmaster,%01010100,i2cfast,i2cbyte 'setup i2c master with keyboard slave
hi2cin [keyboard],0,(keycheck,keyraw,keyascii,keynum)
'sertxd(#b23,",",#b24,cr,lf)
if keycheck<> 1 then
keyraw = 0
goto getakey 'if b0 != 1, then set received byte to 0
else
'sertxd ("got a key")
hi2cout 0,(0)
endif 'reset keyboard status byte
if keynum=11 then powersaversetup
hi2csetup i2cmaster, alfat, i2cfast, i2cbyte
return
~thanks, Patrick
p.s. for completeness here is the keyboard moniter code:
Code:
#picaxe 28x2
symbol keyraw=b0
symbol keycheck=b1
symbol keyascii=b2
symbol keynum=b3
symbol powerstate=b4
EEPROM $00,("?9?5312C?A864?'?") ' Function keys
EEPROM $10,("?????Q1???ZSAW2?") ' Main keyboard keys
EEPROM $20,("?CXDE43?? VFTR5?")
EEPROM $30,("?NBHGY6???MJU78?")
EEPROM $40,("?,KIO09??./L;P-?")
EEPROM $50,("??'?[=????",181,"]?#?") '"??'?[=?????]???")
EEPROM $60,("?",218,"????",127,"??1?",127,"7???") ' Numeric keypad keys
EEPROM $70,("0.",180,"5",126,179,"??B+3-*9??")
startup:
'setfreq m8
put 0,0
hi2csetup i2cslave,%01010100
pause 500
'kbled %10000101 'disable LED blinking (enable capslock and scroll lock, disable numlock)
main:
pause 300
'sertxd("getting key ")
kbin b0 'grab one character
'sertxd("got key ")
'sertxd(#b0)
'sertxd(cr)
get 0,b1
if b1=1 then main 'if status=ready, discard character
put 1,b0 'if status <> ready, store character
read b0,b2 'read eeprom for ascii
put 2,b2
select case b0 'numbers or significant commands
case 69
b3=0
case 22
b3=1
case 30
b3=2
case 38
b3=3
case 37
b3=4
case 46
b3=5
case 54
b3=6
case 61
b3=7
case 6
b3=8
case 70
b3=9
'case 63 'sleep button
' powerstate=1
' b3=11 'sleep command on master
'case 94 'wake up button
' high A.3
' powerstate=0
' b3=12
' pause 500
' low A.3
else
b3=10
endselect
put 3,b3
put 0,1 'update status=ready
pause 400
'debug
goto main