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:
debug
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
'************************
'******Goto Section******
'************************
'**************
'***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
'************************
'***count for time set***
'************************
count_t:
let b13 = b13 + 1 'add on for clock chnage count
if b13 = 10 then goto set_time 'check for clock change
goto main
'**************************
'******///Set Time\\\******
'***including all gosubs***
'**************************
set_time:
sound 6,(120,10)
set_time1:
sertxd (#hour,44,#mins,13,10)
if pin2 = 1 then gosub add_one 'check for value increase
if pin0 = 0 then set_time1 'check for finish clock change
goto set_clock 'goto set clock to write new data to the clock
add_one:
let pins = %00000000
let mins = mins + 1
pulsout 1,10
pause 500
if mins = 60 then gosub add_hour
let pins = %00000001
return
add_hour:
let mins = 0
pulsout 3,10
let hour = hour + 1
pulsout 2,10
if hour = 24 then gosub set_0
return
set_0:
let hour = 0
pulsout 4,10
return
'********************
'***Set alarm Time***
'********************
set_alarm:
'start by displaying current alarm time
'this needs to be read from eeprom and checked to see if data is present
hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte
hi2cin [%10100000],1,(Amin)
hi2cin [%10100000],2,(Ahour)
pause 20
if Amin > 60 then gosub Aminsset
if Ahour > 24 then gosub Ahourset
'*********************
'***show alarm mins***
'*********************
set_Amin:
let b11 = 0
let pins = %00000000
pulsout 3,10
set_acm:
if b11 = Amin then set_Ahour
let b11 = b11 + 1
pulsout 1,10
sertxd (#b11,13,10)
if b11 <= Amin then set_acm
'**********************
'***show alarm hours***
'**********************
set_Ahour:
let b12 = 0
let pins = %00000000
pulsout 4,10
set_ach:
if b12 = Ahour then alarm_set
let b12 = b12 + 1
pulsout 2,10
sertxd (#b12,13,10)
if b12 <= Ahour then set_ach
sound 6,(120,10)
alarm_set:
let pins = %00000001
sertxd ("alarm: ",#Ahour,44,#Amin,13,10)
if pin2 = 1 then gosub addalarm
if pin0 = 0 then alarm_set
goto writedata
addalarm:
let Amin = Amin + 1
pulsout 1,10
pause 250
if Amin = 60 then gosub addAhour
return
addAhour:
let Amin = 0
pulsout 3,10
let Ahour = Ahour + 1
pulsout 2,10
if Ahour = 24 then gosub set_A0
return
set_A0:
let Ahour = 0
pulsout 4,10
return
writedata:
hi2cout [%10100000],1,(Amin)
pause 20
hi2cout [%10100000],2,(Ahour)
pause 20
let temp_m = 0
let temp_h = 0
goto main
'***Check for alarm activation***
check_alarm:
if mins = snoozetime then goto soundalarm
hi2cin [%10100000],1,(Amin)
hi2cin [%10100000],2,(Ahour)
if mins = b18 then main
if Ahour <> hour then main
if Amin <> mins then main
soundalarm:
if pin0 = 1 then snooze
let pins = %00000000
sound 6,(115,10)
let pins = %00000001
sound 6,(120,10)
if pin6 = 0 then setb18
goto soundalarm
snooze:
let b18 = mins
sertxd ("Get Up",13,10)
let snoozetime = Amin + 5
pause 500
goto main
setb18:
let b18 = 0
goto main
'**********************
'******ALL GOSUBS******
'**********************
'***************************
'***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
'*******************************
'***Set clock from user unput***
'*******************************
set_clock:
let b13 = 0
'Convert user input to BCD
b13 = mins / 10 * 16
b13 = mins // 10 | b13
let mins = b13
let b13 = 0
b13 = hour / 10 * 16
b13 = hour // 10 | b13
let hour = b13
let b13 = 0
'set all other data to 00
let sec = $00
let day = $00
let date = $00
let month = $00
let year = $00
let control = %00010000
'Write data to RTC
hi2cout 0,(sec,mins,hour,day,date,month,year,control)
pause 20
sound 6,(120,10)
goto init
'***Set eeprom data***
Aminsset:
let Amin = 0
return
Ahourset:
let Ahour = 0
return