ETITO
The Forum » Projects & Photos > Binary watch, using a 20M
Login Register Search New Posts

William47316

Posted: 6 September 2011 4:45 PM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 5 points!

starting few nights ago finishing today, i have made myself a binary watch/clock using a 20M PICAXE, 3 UCN5841 shift registers 17 LED's (12 red 5 green) and a small jiffy box i have made the ultimate geek clock. the small jiffy box is a bit cramped for space but it does all fit save for the battery, the strap is the base of a walkie talkie watch with its battery powering the clock, most of the code for my 08M picaxe clocks works on it with some slight tweaks for use with the 20M and code to update the shift registers and pulse a pin for the hourly beeper, the beeper is a peizo speaker with a triple 5 oscillator and with the clock's code will beep the number of hours in a 12 hour format

the 3mm LED's are recycled off some old modems and displays the seconds and minutes in 6 bit binary and the hours in 5 bit.  if you be a pansy (meant in a non offensive way) you can take the serial stream from the programming port using a terminal program, but not to worry there is a key to say what place each LED equals, and with a bit of addition you can read the time

 

code for the BINARY CLOCK is below

disablebod 'disable brown out
'declare the variables
symbol seconds = b1 'main seconds variable
symbol minutes = b2 'minutes
symbol hours = b3  'hours variable
symbol hourbeep = b4  'this gets set to the number of beeps +1 the clock does each hour 1 to 12 beeps
symbol beepcount = b5  'counts the number of beeps done
symbol sclk = b.0 ' clock (output pin)
symbol sdata = b.1 ' data (output pin for shiftout)
symbol counter = b6 ' variable used during loop
symbol mask = b7 ' bit masking variable

symbol var_out = b8 ' data variable used during shiftout
symbol bits = 8 ' number of bits
symbol changeflag = bit0 'gets set to 1 when data changes

symbol setflag = bit3 'used in the setting routine
symbol timesetF = bit4 'as above
setint %00000010,%00000010 'pin c.1 with the 1pps source on it

main:


if pinc.4 = 1 then 'detect if the setting PB is pushed
mainloop:
if pinc.4 = 0 then
gosub timeset
end if
goto mainloop
end if


serdata:
if changeflag = 1 then 'if the data has changed
sertxd (#hours,58,#minutes,58,#seconds,13,10) 'send out the hours:minutes:seconds (CR,LF) to the terminal
changeflag = 0 'flag the data as read
gosub shiftupdate 'update the shift registers

end if
if timesetf = 1 then 'when the time is being set it will update the registers and terminal
return
end if
goto main


timeset:


setint %10000,%10000 'set pin c.4 an interrupt for the OK button
seconds = 0 'reset the seconds to 0 and set the time setting flag on
timesetf = 1

timeset2:

'pause 350
gosub serdata
if pinc.3 = 1 then
pause 250
inc minutes
changeflag = 1
if minutes >= 60 then
minutes = 0
end if
end if

if pinc.2 = 1 then
pause 250
inc hours
changeflag = 1
if hours >=24 then
hours = 0
end if
end if

reinit:
if timesetf = 0 then

return
end if
goto timeset2

 

shiftupdate:
var_out = seconds 'seconds shift register
for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB
high sdata ; data high
skipLSB:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 2 , 1

'end of seconds register

var_out = minutes
for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB1
high sdata ; data high
skipLSB1:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 3 , 1

'end of minutes register

var_out = hours
for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB2
high sdata ; data high
skipLSB2:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 4 , 1

'end of hours register
return


interrupt:


if timesetf = 1 then
if pinc.4 = 0 then
pause 250
setflag = 0
timesetf = 0
setint %00000010,%00000010
goto reinit
end if
goto interrupt
end if

'above used in the time setting routine


if pinc.1 = 0 then 'wait till the clock ticker goes low
inc seconds 'increment the seconds variable
if seconds >= 60 then
  seconds = 0
  inc minutes
end if

if minutes >= 60 then
  minutes = 0
  inc hours

'beeper routine

hourbeep = hours + 1 'set the number of times to beep
beepcount = 1 'enable the hourly beep
end if
if hours = 24 then
hours = 0
end if
if hourbeep > 13 then '
hourbeep = hourbeep - 12
end if
if beepcount < hourbeep and beepcount > 0 then
pulsout b.7, 10000 'pulse out pin 7 which has the 555 beeper on it
inc beepcount
end if
if beepcount > hourbeep then
beepcount = 0
end if

'end of beeping routine

changeflag = 1
setint %00000010,00000010
return
end if
goto interrupt

space used on the picaxe 330 bytes out of 4096!!

 

as i still have LOADS of space left on the picaxe i can have a go at adding some features to it, for example an alarm function and a timer (although that may screw with the main time).

 

Great project- thanks for sharing

Ross


============================================================
resistorhelper has a new address www.resistorhelper.org

Andrew H

Posted: 6 September 2011 7:56 PM
 


Member Since:
15 June 2011
Posts: 576
Points: 85

This post was awarded 1 point!

Love it !!!......... Hmmm Would LOVE to see you try to wear it though earport security !!!

As a matter of interest how stable is the internal oscilator ? Note you can tune it a few percent if needed as there is a special command. 

I made a CO2 car racing lap timer the other day and used a dumy pulsout command to get the 1mS resolution of the digital readout 'spot on' over 60 seconds.

If temperature drift was a problem then you could write some code to compensate for temperature changes in the 08M2.  Note there is even an 08M2 command that reads the internal chip temperature...

~ Andrew

 



mookster1

Posted: 7 September 2011 11:54 AM
 



Member Since:
12 February 2011
Posts: 424
Points: 307

This post was awarded 1 point!

Nicely done!  See if you can get the date on there somehow.  I made a simulation once of a 24-hour clock with date yep, leap-years too) out of decade counters, 7-segment decoders and logic gates about 20 something AND gates) which you should be able to find somewhere on here.  It even had a crude hard-wired alarm get to 7:00am and it beeps for a minute.)


============================================================
Matthew - moderator

William47316

Posted: 7 September 2011 12:31 PM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 3 points!

code update and pictures of the inards!

i have added in an alarm function which if you push the minutes set button when it is displaying the main time it will enter the alarm setting mode allowing you to set the minutes, hours and whether the alarm will go off, the interrupt for the ticker is still active so it will still keep the time in the background but the shift registers are set to show the alarm settings, the seconds LEDs show whether the time shown will set the alarm off, all LEDs on = alarm on and the minutes and hours are the time in which it will go off, i have added an extra button which acts as the sleep button and turns the alarm on and off in the setting mode. i have made the alarm routine save the alarm settings to eeprom, at the moment the alarm will go for about one minute doing pulsed beeps, i could get it to beep continuously and maybe get it to stop after the hour ticks over or the sleep button is pressed or the battery dies) like most alarm clocks.

i've also done a few bug fixes and changed some of the inputs around

 

 

 

disablebod
symbol seconds = b1 'main seconds variable
symbol minutes = b2'minutes
symbol hours = b3  'hours variable
symbol hourbeep = b4  'this gets set to the number of beeps +1 the clock does each hour 1 to 12 beeps
symbol beepcount = b5  'counts the number of beeps done
symbol sclk = b.0 ' clock output pin)
symbol sdata = b.1 ' data output pin for shiftout)
symbol counter = b6 ' variable used during loop
symbol mask = b7 ' bit masking variable

symbol var_out = b8 ' data variable used during shiftout
symbol bits = 8 ' number of bits
symbol alarmmin = b9
symbol alarmhour = b10
symbol changeflag = bit0 'detects changes in the clock data so it doesnt spam the display or serial term
symbol alarmflag = bit1 'is 1 when the alarm is set
symbol alsetflag = bit2 'used when setting the alarm
symbol setflag = bit3 'used in the setting routine
symbol timesetF = bit4 'as above
read 0, alarmhour
read 1, alarmmin
read 2,alarmflag
setint %00000010,%00000010

main:


if pinc.4 = 1 then 'detect if the setting PB is pushed
mainloop:
if pinc.4 = 0 then
gosub timeset
end if
goto mainloop
end if

if pinc.2 = 1 then 'minutes set button enters the alarm setting routine
alloop:
if pinc.2 = 0 then
goto alarmset
end if
goto alloop
end if

if pinc.6 = 1 then 'sleep button
alarmflag = 0
end if
serdata:
if changeflag = 1 then
sertxd #hours,58,#minutes,58,#seconds,13,10)
changeflag = 0
gosub shiftupdate

end if
if timesetf = 1 then
return
end if
goto main


timeset:


setint %10000,%10000 'set pin4 an interrupt for the OK button
seconds = 0 'reset the seconds to 0 and set the time setting flag on
timesetf = 1

timeset2:

gosub serdata
if pinc.2 = 1 then
pause 250
inc minutes
changeflag = 1
if minutes >= 60 then
minutes = 0
end if
end if

if pinc.7 = 1 then
pause 250
inc hours
changeflag = 1
if hours >=24 then
hours = 0
end if
end if

reinit:
if timesetf = 0 then

return
end if
goto timeset2



shiftupdate:
var_out = seconds
if alsetflag = 1 then
var_out = alarmflag * 255 'as the alarm flag is one bit set the seconds register all ones
end if

for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB
high sdata ; data high
skipLSB:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 2 , 1

var_out = minutes
if alsetflag = 1 then
var_out = alarmmin
end if

for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB1
high sdata ; data high
skipLSB1:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 3 , 1

var_out = hours
if alsetflag = 1 then
var_out = alarmhour
end if
for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB2
high sdata ; data high
skipLSB2:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 4 , 1

'pulsout 4,1
return


interrupt:
if timesetf = 1 then
if pinc.4 = 0 then
setflag = 0
timesetf = 0
setint %00000010,%00000010
goto reinit
end if
goto interrupt
end if


if pinc.1 = 0 then 'wait till the ticker goes low
inc seconds
    if seconds >= 60 then
        seconds = 0
        inc minutes
    end if

    if minutes >= 60 then
        minutes = 0
        inc hours

    hourbeep = hours + 1 'set the number of times to beep
    beepcount = 1 'enable the hourly beep
    end if
    if hours = 24 then
hours = 0
end if


if hourbeep > 13 then '
hourbeep = hourbeep - 12
end if
if beepcount < hourbeep and beepcount > 0 then
pulsout b.7, 10000
inc beepcount
end if
if beepcount > hourbeep then
beepcount = 0
end if
if alarmflag = 1 and minutes = alarmmin and hours = alarmhour then 'if the alarm flag and the time = each other then set the alarm off by pulsing out the beeper pin
pulsout b.7, 25000
end if
changeflag = 1
setint %00000010,00000010
return
end if
goto interrupt



alarmset: 'alarm setting routine keeps the interrupt for the main time on so it will keep time in the background
alsetflag = 1

if changeflag = 1 then
gosub shiftupdate
changeflag = 0
end if

if pinc.4 = 1 then
alexit:
if pinc.4 = 0 then
write 0, alarmhour 'when exiting the alarm setting save the alarm settings to eeprom
write 1, alarmmin
write 2,alarmflag
alsetflag = 0
goto main
end if
goto alexit
end if

if pinc.2 = 1 then
pause 250
inc alarmmin
changeflag = 1
if alarmmin >= 60 then
alarmmin = 0
end if
end if

if pinc.7 = 1 then
pause 250
inc alarmhour
changeflag = 1
if alarmhour >=24 then
alarmhour = 0
end if
end if



if pinc.6 = 1 then
flagloop:
if pinc.6 = 0 then
changeflag = 1
if alarmflag = 0 then
alarmflag = 1
goto alarmset
end if
if alarmflag = 1 then
alarmflag = 0
goto alarmset
end if
end if
goto flagloop
end if


goto alarmset

 

the timebase im using is from an analogue clock, running from a 1.3 volt regulator involving a red LED, some resistors and a 100µF cap the output of the ticker is rectified and amplified enough to drive the interrupt on the 20 for a stable-ish 1 pulse per second.

the 555 beeper is run off the output pin via the green wire at the bottom of the 20

the 5 wire ribbon goes to the shift register data clock and 3 strobe lines

everything JUST manages to fit inside the small jiffy box


 


============================================================
resistorhelper has a new address www.resistorhelper.org
Last updated 7 September 2011 12:40 PM by William47316

William47316

Posted: 8 September 2011 1:19 AM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 1 point!

quick video of the watch going

http://www.youtube.com/watch?v=x5UBhtwGFgE

unfortunatly my phone wont pick up the beeper so the alarm sound is silent in the video

i have modified the code to do around 1 second beep 1 second silence until the next hour clicks over or the sleep button is pressed


============================================================
resistorhelper has a new address www.resistorhelper.org

William47316

Posted: 26 September 2011 2:41 AM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 3 points!

update: some small tweaks. replaced the LEDs with some fresh 3mm ones, green for the first nybble of the seconds with orange 16 and 32 bit LED's so that 1,2,4,8 are green and 16,32 are orange. similar thing with the minutes only with yellow for the 1,2,4,8 LED's and bright blue for the hours (handy in the dark although at midnight its a bit useless cheeky)

i have ditched the 555 peeper for the picaxe direct driving the piezo with the sound command, a bit louder and bit more control over the sounds for the hourly beep and alarm tone

after some observations, the clock ticker seems to lose about 1 second every six hours or (at least) 4 seconds a day relitive to the more accurate ticker in my big 8 digit clock. im not sure if this is the crystal, the voltage im running it at or the stability of said voltage, at the moment its running with a 4k7 current limit resistor and 3 small silicon diodes (1n4148 i think) gives me about 1.6 volts charging a 1000µF cap near the power connections of the clock divider, the voltage does dip a small amount on my meter but i dont have access to an O'scope so i cant tell if its dropping the voltage below tolerance. im not sure if driving it at full supply (~3.7 -  4.2 from the LiIon) or double 1.5 will improve accuracy maybe just a stablised 1.5 supply either from a real battery or a low quiesent current regulator with some largish caps (i got a few tantulums from the chch robotics club) may improve things

at some stage i may tack on a 1.5 volt cell and see if the accuracy improves

 

current draw: with the red LEDs i had around 3.4mA at midnight and up to around 23mA at 23:59 and all the seconds LED's on (alarm function on in alarm set mode) at 3.7 volts, estimated battery life @540mAh probably 20 hours to a few days, i'll take it off its charger and see how long it lasts before the LEDs become too dim to see

 

future?:

infrared sync function. using a picaxe to tap into the 8 digit clock serial line and send out infra red as serial (at a low baud rate modulated at 40 odd Khz) and recived by the watch to set its time to the second that way, i think the 20 pin picaxes can have a timeout on there serial inputs, i'll have to look into it. so if you accidentally set it to sync you can set the time manually.

multialarm? with the limited displaying capabilities of the binary digits and eeprom memory i could possibly get it to do at least 10 maybe maybe not, there should be plenty of space and variables for it but may be difficult to use easily

reset memory, if the battery comes out keep at least the minute and hour in eeprom so you (a) know when the battery died/got removed when the battery is replaced. and (b) so you can reset the time by only a few minutes instead of resetting the entire time.

 

huge binary clock, i still have a 28 picaxe, so i'll buy up some huge 10 mm LEDs and zippy box etc and give it the full fledge treatment, westminster hourly alarm and all, i'll have to dig out either some ucn5841's or 595's


============================================================
resistorhelper has a new address www.resistorhelper.org

William47316

Posted: 26 September 2011 5:29 PM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 1 point!

it seems i might have slightly damaged (edit HAVE damaged) the 20 pin picaxe as it is drawing 80mA when not attached to anything, the clock will still function but it now puts a significant drain on the battery and goes completely flat after a few hours (estimate less than 10 hours). im not sure if this is because of some hairline shorts that the veroboard had and that had damaged the internals or some latchup condition has permanatly damaged it. i'll do some tests and see if i can find out what had happened otherwise i may have to adapt it to the 28 or just put up with it going flat or get a replacement 20x2 20M etc

 

 

edit: its buggered now, i'll have to save my pennies for another 20 pin picaxe its power rails turned into a resistor, not sure if any of the IO's latched up or its reverse diode failed either way i "let the magic smoke" out


============================================================
resistorhelper has a new address www.resistorhelper.org
Last updated 26 September 2011 6:00 PM by William47316

Andrew H

Posted: 26 September 2011 8:02 PM
 


Member Since:
15 June 2011
Posts: 576
Points: 85

This post was awarded 1 point!

Have you put it into a breadboard and tried to cold boot / program it ?

If you have and confirm it is dead then I may have a spare...  20X2 for 20 points etc...

Did you use a socket ?

~ Andrew



mookster1

Posted: 27 September 2011 1:50 PM
 



Member Since:
12 February 2011
Posts: 424
Points: 307

This post was awarded 1 point!

Wow, you managed to actually KILL a PICAXE! surprise Many a time I have given myself nightmares about possibly damaging my beloved PICAXE (once I was quite sure I had killed it because I accidentally swapped the voltage rails on my breadboard) but have never actually managed to do that.  I saw that you used an analogue clock as the timebase... that is quite awesome.  I wonder what could have possibly killed the PICAXE?


============================================================
Matthew - moderator

David44209

Posted: 27 September 2011 10:01 PM
 


Member Since:
26 October 2004
Posts: 2256
Points: 11672

This post was awarded 1 point!

lol iv killed 2 cypress chips by shoveng 12 vollts down the I/O line by accedent once by brushing a wire on the wrong pin and another wire loom wrong

 

funnny enuf one of the cypress chips dident fully die, just draws 200Mha  and well that I/O dosent work but it still functions

what my boss dosent know is that cypress is still in opperation in one of the prototype PRUs

she gets a bit hot tho drawing 200 Mha so i shoved a heatsink on it and away she went, so to this day it still running as far as i know,

4 months in operation


============================================================
dave's email / sparky114@gmail.com http://img458.imageshack.us/img458/1453/mojo5wp.png

mookster1

Posted: 28 September 2011 10:06 AM
 



Member Since:
12 February 2011
Posts: 424
Points: 307

This post was awarded 1 point!

Crikey.  I figured gross overvoltage would eventually kill a PICAXE, but despite several scares I've never actually managed to kill my 20M.


============================================================
Matthew - moderator

Andrew H

Posted: 28 September 2011 10:29 AM
 


Member Since:
15 June 2011
Posts: 576
Points: 85

This post was awarded 1 point!

I Love the beasty robustness of these chips !

I find that over volts just tends to warp the internal osilator to a point where serial comms becomes hard and the tune commands start to output oriental tuning / musical pitch intervals.

It is over voltage of a pin w.r.t the operating voltage power supply since over volts will try to shnt the energy away from the pin direct to VCC/Vdd  Most over voltages are shunted to Vcc / +ve and or -ve via the internal protection diodes on each pin (100mA rated) ...  PROVIDED you do not have a plug pack / or half decent battery, power supply behind the volts.  In fact to demo this one day I intend to make an 08M bridge rectifier that rectifies and counts low voltage power 50Hz AC pulses on an input ( bridge rectifier pin), measures and counts the Hz and or uses the 50 Hz and spits out DC on the +ve and -ve power pins which would have a smoothing electrolytic capacitor on them...

Perhaps Output the result as a decimal blink value on an LED ?

Serial binary code on a single LED ?

~ Andrew



William47316

Posted: 28 September 2011 6:28 PM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 1 point!

 

Have you put it into a breadboard and tried to cold boot / program it ?

If you have and confirm it is dead then I may have a spare...  20X2 for 20 points etc...

Did you use a socket ?

 

i did use a socket so the chip replaceable, it was programmable while the picaxe was damaged but functional. granted i did try to "blow out" the resistance accross the power rails reverse and foward that might have done some of it

next time i order from the free parts you can throw it in, i might send a few $ your way or ross (i have the goldcard bank acc number so i can shift some $ that way)

when i found out the picaxe was drawing 80mA and opened up the box the chip was a little warm, not toasty but a bit above ambient at least


============================================================
resistorhelper has a new address www.resistorhelper.org

William47316

Posted: 15 October 2011 12:55 AM
 



Member Since:
17 May 2005
Posts: 2001
Points: 1778

This post was awarded 2 points!

update:

replaced the 20x2 in the watch and i have added in a few extras to the code

- time memory: if the battery is removed it will store the hours and minutes (and the date) in eeprom

- calender: does two digit years up to about 2063 (limit of the displaying LED's) and calculates if its a leap year and displays the day and month

i also replaced the crystal for the clock divider and seems to be less lossy, and seems to stay in sync with my big clock at least for now, i will check the performance of that aspect over the next couple of days

some future additions:

automatic daylight saving mode, now i have added the calender function i can do that. eg when daylight savings starts and ends, automatically add or remove an hour

code is below

data 11,(31,28,31,30,31,30,31,31,30,31,30,31) 'regular year days of the month
data 31,(31,29,31,30,31,30,31,31,30,31,30,31) 'for leap years

disablebod
symbol seconds = b1 'main seconds variable
symbol minutes = b2'minutes
symbol hours = b3  'hours variable
symbol hourbeep = b4  'this gets set to the number of beeps +1 the clock does each hour 1 to 12 double beeps
symbol beepcount = b5  'counts the number of beeps done
symbol sclk = b.0 ' clock (output pin)
symbol sdata = b.1 ' data (output pin for shiftout)
symbol counter = b6 ' variable used during loop
symbol mask = b7 ' bit masking variable

symbol var_out = b8 ' data variable used during shiftout
symbol bits = 8 ' number of bits
symbol alarmmin = b9
symbol alarmhour = b10
symbol year = b11
symbol month = b12
symbol day = b13
symbol daysin = b14
symbol leapcalc = w8
symbol monthloc = b18

symbol changeflag = bit0 'detects changes in the clock data so it doesnt spam the display or serial term
symbol alarmflag = bit1 'is 1 when the alarm is set
symbol alsetflag = bit2 'used when setting the alarm
symbol setflag = bit3 'used in the setting routine
symbol timesetF = bit4 'as above
symbol alarmgoing = bit5
symbol isleapyear = bit6
symbol dateveiwer = bit7
read 0, alarmhour
read 1, alarmmin
read 2, alarmflag
read 3, hours
read 4, minutes
read 8, day
read 9, month
read 10, year


if day = 0 or month = 0 or year = 0 then 'if the date is read 0 set it to 1st january 2010
day = 1
month = 1
year = 10
end if

setint %00000010,%00000010

main:


if pinc.4 = 1 then 'detect if the setting PB is pushed
mainloop:
if pinc.4 = 0 then
goto timeset
end if
goto mainloop
end if

if pinc.2 = 1 then
alloop:
if pinc.2 = 0 then
goto alarmset
end if
goto alloop
end if


if pinc.7 = 1 then
dateloop:
if pinc.7 = 0 then
goto dateveiw
end if
goto dateloop
end if

if pinc.6 = 1 then
alarmflag = 0
alarmgoing = 0
low b.7
end if
serdata:
write 3, hours
write 4, minutes
if changeflag = 1 then
sertxd (#hours,58,#minutes,58,#seconds,13,10,#alarmhour,58,#alarmmin,9,#alarmflag,13,10,#day,"/",#month,"/",#year,13,10)
changeflag = 0
gosub shiftupdate

end if
if timesetf = 1 then
return
end if
goto main


timeset:


setint off 'set pin4 an interrupt for the OK button
seconds = 0 'reset the seconds to 0 and set the time setting flag on
timesetf = 1

timeset2:
if pinc.4 = 1 then
Tsetexit:
if pinc.4 = 0 then
'write 0, alarmhour
'write 1, alarmmin
'write 2,alarmflag
'alsetflag = 0
setflag = 0
timesetf = 0
setint %00000010,%00000010
goto main
end if
goto tsetexit
end if
'pause 350
gosub serdata
if pinc.2 = 1 then
pause 250
inc minutes
changeflag = 1
if minutes >= 60 then
minutes = 0
end if
end if

if pinc.7 = 1 then
pause 250
inc hours
changeflag = 1
if hours >=24 then
hours = 0
end if
end if


goto timeset2

alarmset:
alsetflag = 1

if changeflag = 1 then
gosub shiftupdate
changeflag = 0
end if

if pinc.4 = 1 then
alexit:
if pinc.4 = 0 then
write 0, alarmhour
write 1, alarmmin
write 2,alarmflag
alsetflag = 0
goto main
end if
goto alexit
end if

if pinc.2 = 1 then
pause 250
inc alarmmin
changeflag = 1
if alarmmin >= 60 then
alarmmin = 0
end if
end if

if pinc.7 = 1 then
pause 250
inc alarmhour
changeflag = 1
if alarmhour >=24 then
alarmhour = 0
end if
end if



if pinc.6 = 1 then
flagloop:
if pinc.6 = 0 then
changeflag = 1
if alarmflag = 0 then
alarmflag = 1
sound b.7,(100,25)
goto alarmset
end if
if alarmflag = 1 then
alarmflag = 0
goto alarmset
end if
end if
goto flagloop
end if


goto alarmset


shiftupdate:

var_out = seconds
if alsetflag = 1 then
var_out = alarmflag * 255
end if
if dateveiwer = 1 then
var_out = year
end if

for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB
high sdata ; data high
skipLSB:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 2 , 1

var_out = minutes
if alsetflag = 1 then
var_out = alarmmin
end if
if dateveiwer = 1 then
var_out = month
end if



for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB1
high sdata ; data high
skipLSB1:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 3 , 1

var_out = hours
if alsetflag = 1 then
var_out = alarmhour
end if

if dateveiwer = 1 then
var_out = day
end if


for counter = 1 to bits
mask = var_out & 1
low sdata  'data low
if mask = 0 then skipLSB2
high sdata ; data high
skipLSB2:
pulsout sclk,1
var_out = var_out / 2
next counter
pulsout 4 , 1

'pulsout 4,1
return


interrupt:



if pinc.1 = 0 then
inc seconds
    if seconds >= 60 then
        seconds = 0
        inc minutes
    end if

    if minutes >= 60 then
        minutes = 0
        inc hours

    hourbeep = hours + 1 'set the number of times to beep
    beepcount = 1 'enable the hourly beep
    end if
    if hours = 24 then
hours = 0
inc day
gosub dateprocess
end if


if hourbeep > 13 then '
hourbeep = hourbeep - 12
end if
if beepcount < hourbeep and beepcount > 0 then
sound b.7,(100,10)
inc beepcount
end if
if beepcount > hourbeep then
beepcount = 0
end if
if alarmflag = 1 and minutes = alarmmin and hours = alarmhour then
alarmgoing = 1
end if
if alarmgoing = 1 and hours = alarmhour then
sound b.7,(100,10)
else
low b.7
end if
changeflag = 1
setint %00000010,00000010
return
end if
goto interrupt

dateprocess:
yearinc:
if year > 63 then
year = 1
end if

'calculate weather the set year is a leep year or not
leapcalc = year +2000 * 100 'as the picaxe cant handle floating points you have to shift over a few places
leapcalc = leapcalc / 4 'divide it by 4
leapcalc = leapcalc // 100 'stick the remainder in the variable
if leapcalc = 0 then 'if it divided evenly its a leap year
isleapyear = 1
else if leapcalc <> 0 then
isleapyear = 0
end if


monthinc:

'select which calander to use
if isleapyear = 1 then
monthloc = month + 30
else
monthloc = month + 10
end if

read monthloc, daysin

if day > daysin then 'determine whether its the end of the month
day = 1
monthset:
inc month
if month > 12 then 'determine whether its the end of the year
month = 1
yearset:
inc year
goto yearinc 'recalculate whether its a leap year again
end if
goto monthinc
end if

'store the new date in the eeprom
write 8, day
write 9, month
write 10, year
return

dateveiw: 'routine to veiw and set the date
dateveiwer = 1
gosub shiftupdate

idle:
if pinc.4 = 1 then 'detect if the setting PB is pushed
mainloop2:
if pinc.4 = 0 then
goto dateset
end if
goto mainloop2
end if



idle3:
if pinc.6 = 1 then
if pinc.6 = 0 then
dateveiwer = 0
goto main
end if
goto idle3
end if

goto idle

dateset:
leapcalc = year +2000 * 100
leapcalc = leapcalc / 4
leapcalc = leapcalc // 100
if leapcalc = 0 then
isleapyear = 1
else if leapcalc <> 0 then
isleapyear = 0
end if
if isleapyear = 1 then
monthloc = month + 30
else
monthloc = month + 10
end if

gosub shiftupdate

if pinc.2 = 1 then
pause 250
inc month
if month > 12 then
month = 1
end if
end if


if pinc.6 = 1 then
pause 250
inc year

end if

if pinc.7 = 1 then
inc day
read monthloc, daysin
if day > daysin then
day = 1
end if

end if

if pinc.4 = 1 then 'detect if the setting PB is pushed
mainloop3:
if pinc.4 = 0 then
write 8, day
write 9, month
write 10, year
dateveiwer = 0
goto main

end if
goto mainloop3
end if

goto dateset


============================================================
resistorhelper has a new address www.resistorhelper.org

Andrew H

Posted: 15 October 2011 9:35 AM
 


Member Since:
15 June 2011
Posts: 576
Points: 85

This post was awarded 1 point!

Okay... so where is the ewechube video of it in ACTIon !!!!

~ Andrew



 
Page:   1   2  

You need to be a member to post.