Hi
I am just starting to learn basic for pic after using logicator.
I am building an LED clock that uses shift registers and a ring of LEDs around the edge of the clock for the seconds and four 7 segment displays for the hours and minutes (controlled by 4026 chips). The chip I am using is an 18m2 so pretty much, every time I send a pulse out of C.1, a new LED will light to show an extra second. A pulse from C.0 clears the LEDs. B.7 advances the minutes, B.6 clears the minutes. B.5 increments the hours and B.4 clears the hours. The time is read from a time keeping chip over I2C.
As I am just starting with basic, could someone please check over my code and point out my errors and if possible, help me optimise it.
Thanks
I am just starting to learn basic for pic after using logicator.
I am building an LED clock that uses shift registers and a ring of LEDs around the edge of the clock for the seconds and four 7 segment displays for the hours and minutes (controlled by 4026 chips). The chip I am using is an 18m2 so pretty much, every time I send a pulse out of C.1, a new LED will light to show an extra second. A pulse from C.0 clears the LEDs. B.7 advances the minutes, B.6 clears the minutes. B.5 increments the hours and B.4 clears the hours. The time is read from a time keeping chip over I2C.
As I am just starting with basic, could someone please check over my code and point out my errors and if possible, help me optimise it.
Thanks
Code:
#picaxe 18m2
start0:
i2cslave %11010000,i2cslow, i2cbyte
readi2c 0, (b0,b1,b2)
;spam pulses to set up the second hand
b10=0
looping:
if b1<>b10 then
high C.1
pause 1
low C.1
inc b0
goto looping
endif
;spam pulses to set up the minute digits on 7 seg
b10=0
looping1:
if b2<>b10 then
high B.7
pause 1
low B.7
inc b0
goto looping1
endif
;spam pulses to set up the hour digits on 7 seg
b10=0
looping2:
if b3<>b10 then
high B.5
pause 1
low B.5
inc b0
goto looping2
endif
stop
;increment leds every second by sending pulse out of C.1
start1:
secondsmainloop:
i2cslave %11010000,i2cslow, i2cbyte
readi2c 0, (b0)
b10=b0+1
if b10 = 60 then
high C.0
pause 1
low C.0
goto secondsmainloop
endif
secondincloop:
if b0<>b10 then
goto secondincloop
endif
high C.1
pause 1
low C.1
goto secondsmainloop:
;increment 7 seg count every minute by sending pulse out of B.7
start2:
minutesmainloop:
i2cslave %11010000,i2cslow, i2cbyte
readi2c 0, (b1)
b10=b1+1
if b11 = 60 then
high B.6
pause 1
low B.6
goto minutesmainloop
endif
minuteincloop:
if b1<>b11 then
goto minuteincloop
endif
high B.7
pause 1
low B.7
goto minutesmainloop
;increment 7 seg count every hour by sending pulse out of B.5
start3:
hoursmainloop:
i2cslave %11010000,i2cslow, i2cbyte
readi2c 0, (b2)
b12=b2+1
if b10 = 12 then
high B.4
pause 1
low B.4
goto hoursmainloop
endif
hourincloop:
if b2<>b12 then
goto hourincloop
high B.5
pause 1
low B.5
endif
goto hoursmainloop: