#picaxe 28x1
'------------------------------------------------------------------------------'
'first attempt at binary clock using ds1338 and 28x1
'with multiplexed LEDs
'------------------------------------------------------------------------------'
main:
setfreq m8 'sets operating frequency at power-on
i2cslave %11010000, i2cfast_8, i2cbyte 'initiates and sets DS1307 slave address
i2cslave %11010000, i2cfast_8, i2cbyte 'initiates I2C for ds1307
let dirsc=%11100000 'sets pins 5,6,7 on port c for ouputs
write_time:
if pin2=1 then write_time 'loops until button released
writei2c 0, (b0, b1, b2) 'writes the 'set' hrs,mins,secs into ds1307
low portc 5 'ensure port c o/p 5 is off
low portc 6 'ensure port c o/p 6 is off
low portc 7 'ensure port c o/p 7 is off
readtime:
if pin2=1 then hrs_set 'jump to routine for setting the time
readi2c 0, (b0, b1, b2) 'read secs,mins,hrs and store in variables
'------------------------------------------------------------------------------'
'Convert BCD to BINARY and display results
'------------------------------------------------------------------------------'
let b6=bcdtobin b0 'converts bcd secs to binary
low portc 5 'switches off 'hrs' LEDs
let pins=%00000000 'resets outputs to elliminate led blurring
high portc 7 'switches on 'secs' LEDs
let pins = b6 'turns on LEDs to display secs
pause 6 'delay to ensure even 'secs' brilliance
let b6=bcdtobin b1 'converts bcd mins to binary
low portc 7 'switches off 'secs' LEDs
let pins=%00000000 'resets outputs to elliminate led blurring
high portc 6 'switches on 'mins' LEDs
let pins = b6 'turns on LEDs to display mins
pause 4 'delay to ensure even 'mins' brilliance
let b6=bcdtobin b2 'converts bcd hrs to binary
low portc 6 'switches off 'mins' LEDs
let pins=%00000000 'resets outputs to elliminate led blurring
high portc 5 'switches on 'hrs' LEDs
let pins = b6 'turns on LEDs to display hrs
goto readtime
'------------------------------------------------------------------------------'
'Routine for pre-setting the HOURS
'------------------------------------------------------------------------------'
hrs_set:
if pin2=1 then hrs_set 'loop until button6 is released
low portc 7 'switches off 'secs' LEDs
low portc 6 'switches off 'mins' LEDs
high portc 5 'switches on 'hrs' LEDs
b8=0 'resets b8(hrs) to zero for hrs setting
hrs_inc:
if pin2=1 then mins_set 'jump to routine for setting the mins
if pin1=0 then hrs_inc 'loop until button7 is pressed
hrs_loop:
if pin2=1 then mins_set 'jump to routine for setting the mins
if pin1=1 then hrs_loop 'loop until button7 is released
b8=b8+1 'increment hrs variable by 1
let pins=b8 'display hrs on leds in binary
if b8>24 then let b8=0 'resets b8 to zero
end if
let b2=bintobcd b8 'convert to bcd to load into b2 for RTC
if pin2=1 then mins_set 'jump to routine for setting the mins
pause 10
goto hrs_inc
'------------------------------------------------------------------------------'
'Routine for pre-setting the MINUTES
'------------------------------------------------------------------------------'
mins_set:
if pin2=1 then mins_set 'loop until button6 is released
low portc 5 'switches off 'secs' LEDs
low portc 7 'switches off 'hrs' LEDs
high portc 6 'switches on 'mins' LEDs
b8=0 'resets b8(hrs) to zero for mins setting
mins_inc:
if pin2=1 then secs_set 'jump to routine for setting the secs
if pin1=0 then mins_inc 'loop until button7 is pressed
mins_loop:
if pin2=1 then secs_set 'jump to routine for setting the secs
if pin1=1 then mins_loop 'loop until button7 is released
b8=b8+1 'increment mins variable by 1
let pins=b8 'display mins on leds in binary
if b8> 60 then let b8=0 'resets b8 to zero
end if
let b1=bintobcd b8 'convert to bcd to load into b1 for RTC
if pin2=1 then secs_set 'jump to routine for setting the secs
pause 10
goto mins_inc
'------------------------------------------------------------------------------'
'routine for pre-setting the SECONDS
'------------------------------------------------------------------------------'
secs_set:
if pin2=1 then secs_set 'loop until button6 is released
low portc 5 'switches off 'mins' LEDs
low portc 6 'switches off 'hrs' LEDs
high portc 7 'switches on 'secs' LEDs
b8=0 'resets b8(hrs) to zero for secs setting
secs_inc:
if pin2=1 then write_time: 'goto write_time: routine for starting the clock
if pin1=0 then secs_inc 'loop until button7 is pressed
secs_loop:
if pin2=1 then write_time: 'goto write_time: routine for starting the clock
if pin1=1 then secs_loop 'loop until button7 is released
b8=b8+1 'increment secs variable by 1
let pins=b8 'display hrs on leds in binary
if b8>60 then let b8=0 'resets b8 to zero
end if
let b0=bintobcd b8 'convert to bcd to load into b0 for RTC
if pin2=1 then write_time: 'goto write_time: routine for starting the clock
pause 10
goto secs_inc