i have writen a programme which runs fine when simulated, even over a period over a couple hours. but when loaded onto my 28x1 it bugs and does some strange stuff, it loads random numbers into the variables and displays randomly on the display. i dont understand what is going on
________
Bmw x-coupe
Code:
symbol control = b0
symbol temp_byte = b1
symbol temp_m = b2
symbol temp_h = b3
symbol sec = b4
symbol mins = b5
symbol hour = b6
symbol day = b7
symbol date = b8
symbol month = b9
symbol year = b10
'b11-b13 used for some switch counts
symbol Amin = b14
symbol Ahour = b15
symbol snoozetime = b16
init:
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
hi2cin 0,(sec,mins,hour,day,date,month,year,control)
sertxd (#sec,#mins,#hour,#day,#date,#month,#year,#control,13,10) 'send data to computer
if control = %00010000 then main 'check RTC to see if has data
'if the RTC has no data then write new values
let sec = $00
let mins = $00
let hour = $00
let day = $00
let date = $00
let month = $00
let year = $00
let control = %00010000 'set LED to flash
sertxd (#sec,#mins,#hour,#day,#date,#month,#year,#control,13,10) 'send data to computer
hi2cout 0,(sec,mins,hour,day,date,month,year,control) 'wrtie RTC
pause 20
'********************
'***Main Programme***
'********************
main:
let pins = %00000001 'Switch on display
hi2cin [%11010000],0,(sec,mins,hour,day,date,month,year) 'read RTC
pause 20
gosub bcd_decimal 'convert data to readible info
if temp_m <> mins then set_min 'check mins display
if temp_h <> hour then set_h 'check hour display
sertxd ("Time: ",#hour,44,#mins,44,#sec,13,10) 'send time to computer if pin1 =1 and pin6 = 1 then set_alarm
'if pin6 = 1 and pin1 = 1 then set_alarm
'if pin1 = 1 then goto count_t
'if pin6 = 1 then check_alarm 'check for time set
goto main
'**************
'***Set Mins***
'**************
set_min:
let b11 = 0
let pins = %00000000 'Switch off display
let temp_m = mins
pulsout 3,10 'reset mins display
set_cm:
if b11 = mins then main 'check varible to ensure no over flow on display
let b11 = b11 + 1
pulsout 1,10 'increse mins display by 1
if b11 < mins then set_cm
goto main
'***************
'***Set hours***
'***************
set_h:
let b12 = 0
let pins = %00000000 'Switch off display
let temp_h = hour
pulsout 4,10 'reset hour display
set_ch:
if b12 = hour then main 'check varible to ensure no over flow on display
let b12 = b12 + 1
pulsout 2,10 'increse hour display by 1
if b12 < hour then set_ch
goto main
'***************************
'***Chanck BCD to Decimal***
'***************************
bcd_decimal:
let temp_byte = sec & %11110000 / 16 * 10
let sec = sec & %00001111 + temp_byte
let temp_byte = mins & %11110000 / 16 * 10
let mins = mins & %00001111 + temp_byte
let temp_byte = hour & %11110000 / 16 * 10
let hour = hour & %00001111 + temp_byte
let temp_byte = day & %11110000 / 16 * 10
let day = day & %00001111 + temp_byte
let temp_byte = date & %11110000 / 16 * 10
let date = date & %00001111 + temp_byte
let temp_byte = month & %11110000 / 16 * 10
let month = month & %00001111 + temp_byte
let temp_byte = year & %11110000 / 16 * 10
let year = year & %00001111 + temp_byte
return
Bmw x-coupe
Last edited: