Below is the PIC basic pro code that I wrote some time ago for my
first clock. It works very well for me so I have used it, unchanged
in several other clocks I have put together since. Your mileage my
vary. ;)
Hope this helps.
Chris
'This is the start of the time and date setting routine
'The date is scrolled in first and the month will begin to blink
'When the adv button is pressed, the month will increment by 1
'If the adv button is held down the month will increment automatically
'When the set button is pressed the day will start to blink and so on
'Once the entire date has been set the time will scroll in and time is
set the same way
'with the exception of seconds which will increment by 10 starting
from 0
'Hours are set in 24 hour format to keep the date correct
'When the seconds are blinking and the set button is pressed this will
"set"
'the time by writing all of the time and date values to the DS1302 and
then the
'clock will go back to display mode
set_date_time:
gosub burst_read 'Read in the time and date
seconds = %00000000 'Zero out the seconds since they dont
matter by the time you get there
gosub display_rotate_out
gosub rotate_date_in 'Bring in the date
set_month:
gosub display_date 'Complete the scroll in
for x = 1 to 75 'Leave the month on for 750ms while
checking the buttons
Button SET_BTON,0,255,0,B0,1,set_date
Button ADV_BTON,0,75,25,B1,1,set_month_work
pause 10
next x
SHiftout NIX_1_DTA,NIX_1_CLK,1,[255] : Pulsout NIX_1_LCH,1 'Blank
the month
for x = 1 to 25 'Leave the month blanked for 250ms while
checking the buttons
pause 10
Button SET_BTON,0,255,0,B0,1,set_date
Button ADV_BTON,0,75,25,B1,1,set_month_work
next x
Goto set_month 'If nothing pressed, do it again
'This routine will increment the month by one
'Only used if the adv button is pressed above
set_month_work:
month = ((month & $f0)>>4*10)+(month & $0f) 'Convert month to
binary
month = month + 1
if month > 12 then month = 1
month = ((month/10)<<4)+(month//10) 'Convert month to BCD
Goto set_month
set_date:
gosub display_date 'Make sure that all tubes are on
for x = 1 to 75
Button SET_BTON,0,255,0,B0,1,set_year
Button ADV_BTON,0,75,25,B1,1,set_date_work
pause 10
next x
SHiftout NIX_2_DTA,NIX_2_CLK,1,[255] : Pulsout NIX_2_LCH,1
for x = 1 to 25
pause 10
Button SET_BTON,0,255,0,B0,1,set_year
Button ADV_BTON,0,75,25,B1,1,set_date_work
next x
goto set_date
set_date_work:
date = ((date & $f0)>>4*10)+(date & $0f)
date = date + 1
if date > 31 then date = 1
date = ((date/10)<<4)+(date//10)
goto set_date
set_year:
gosub display_date
for x = 1 to 75
Button SET_BTON,0,255,0,B0,1,set_time
Button ADV_BTON,0,75,25,B1,1,set_year_work
pause 10
next x
SHiftout NIX_3_DTA,NIX_3_CLK,1,[255] : Pulsout NIX_3_LCH,1
for x = 1 to 25
pause 10
Button SET_BTON,0,255,0,B0,1,set_time
Button ADV_BTON,0,75,25,B1,1,set_year_work
next x
goto set_year
set_year_work:
year = ((year & $f0)>>4*10)+(year & $0f)
year = year + 1
if year > 99 then year = 7
year = ((year/10)<<4)+(year//10)
goto set_year
set_time:
gosub display_rotate_out
gosub rotate_time_in
set_hours:
gosub display_time
for x = 1 to 75
Button SET_BTON,0,255,0,B0,1,set_minutes
Button ADV_BTON,0,75,25,B1,1,set_hours_work
pause 10
next x
SHiftout NIX_1_DTA,NIX_1_CLK,1,[255] : Pulsout NIX_1_LCH,1
for x = 1 to 25
pause 10
Button SET_BTON,0,255,0,B0,1,set_minutes
Button ADV_BTON,0,75,25,B1,1,set_hours_work
next x
goto set_hours
set_hours_work:
hours = ((hours & $f0)>>4*10)+(hours & $0f)
hours = hours + 1
if hours > 23 then hours = 0
hours = ((hours/10)<<4)+(hours//10)
goto set_hours
set_minutes:
gosub display_time
for x = 1 to 75
Button SET_BTON,0,255,0,B0,1,set_seconds
Button ADV_BTON,0,75,25,B1,1,set_minutes_work
pause 10
next x
SHiftout NIX_2_DTA,NIX_2_CLK,1,[255] : Pulsout NIX_2_LCH,1
for x = 1 to 25
pause 10
Button SET_BTON,0,255,0,B0,1,set_seconds
Button ADV_BTON,0,75,25,B1,1,set_minutes_work
next x
goto set_minutes
set_minutes_work:
minutes = ((minutes & $f0)>>4*10)+(minutes & $0f)
minutes = minutes + 1
if minutes > 59 then minutes = 1
minutes = ((minutes/10)<<4)+(minutes//10)
goto set_minutes
set_seconds:
gosub display_time
for x = 1 to 75
Button SET_BTON,0,255,0,B0,1,set_datetime_work
Button ADV_BTON,0,75,25,B1,1,set_seconds_work
pause 10
next x
SHiftout NIX_3_DTA,NIX_3_CLK,1,[255] : Pulsout NIX_3_LCH,1
for x = 1 to 25
pause 10
Button SET_BTON,0,255,0,B0,1,set_datetime_work
Button ADV_BTON,0,75,25,B1,1,set_seconds_work
next x
goto set_seconds
set_seconds_work:
seconds = ((seconds & $f0)>>4*10)+(seconds & $0f)
seconds = seconds + 10
if seconds > 50 then seconds = 0
seconds = ((seconds/10)<<4)+(seconds//10)
goto set_seconds
'When the set button is pressed while the seconds are blinking
'all values are written to the DS1302 and the display is returned to
normal
set_datetime_work:
gosub burst_write
goto main
end
On Nov 15, 8:33 am, Shane Ellis <[email protected]> wrote:
> all the hardware is ready for my first clock. Really basic 6 tube,
> no alarm yet, no GPS, no bells and whistles. If I turn it on, it will
> count just fine, from 12:00:01, to 12:00:01etc. I want to be able to
> set this clock to a desired time, and let it go after I set it. The
> coding has me baffled though. I am using the gosub command to name
> the binary number groups ":one, two, three and so on" and I was
> thinking of using an "if then" command to get the clock to cycle
> through numbers in the desired order, so it can be set.
> Any help appreciated.
> Shane
--
You received this message because you are subscribed to the Google Groups
"neonixie-l" group.
To post to this group, send an email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/neonixie-l?hl=en-GB.