how to edit time date /alarm in axe033 using keypad

jimmy88

New Member
im really new in picaxe world i really need help ,i have a project that i should make a clock that the user can set the time/date and alarm(or target timing) using keypad and then this alarm will let a robot work the data will be sent wirelssly to the robot (ex...like every day at 3:00 to 4:00 the robot will start working and the data will be transimitted to the robot using xbee

i have two quessstions
1-
is it possible to set the time/date and set alarm without re-programming using a key pad with axe033 is there any additional things should be added ,whats the best picaxe microcontrolller to be used in this case,can some one show me a sample code .

2-
i want to send data of the time/date using xbee module
i tried this code but i think its not working
after seting the date/time
using
i2cslave %11010000,i2cslow,i2cbyte
writei2c 0,($00,$40,$02,$08,$24,$05,$08,$10)
end

then i downloaded this code in 1st xbee module
init: high 7
pause 100
i2cslave %11010000,i2cslow,i2cbyte
main:
readi2c 0,(b0,b1,b2)
serout 7,t2400,($55,$55,$55,b0,b1,b2)
pause 10
goto main

after that i downloaded this code to the second module
main:serin 7,t2400,($55,$55,$55),b0,b1,b2
if b2<>$02 then main
if b1<>$50 then main
high 3
pause 60000
low 3
goto main
im using two axe210 boards with xbee fitted and picaxe 18x the axe033 module is connected with the 1st axe210 by scl ,sda +v,0v
when connecting axe033 to a seprate microcontroler the time /date is showing on the lcd fine but when i use axe 210 microcontroller time get changes and wear characters appears on the lcd

any help
 

moxhamj

New Member
Yes you can set the time with buttons, but if you are new to picaxe I'm not sure I'd start with this project! An 18X is the minimum chip as you need lots of lines of code. It is about a week of coding, and the brain needs to be in tip-top condition so no alcohol while writing this code!

I'm posting the code below not so much as an example but rather just to show how complex it is. This is not code for the axe33 board as there were not enough outputs so all the outputs to the display on this code go through two HC595 chips and there is some code associated with that which can be ignored. But large parts of the rest of the code are to do with setting the time using just two buttons. The two buttons are on pin0 and pin1 and both picaxe lines have 10k pulldown resistors on those lines. The pushbutton makes the line go high. The pin0 button counts up, and the pin1 button is a menu button. Push the menu button and the display might show "wednesday". Push the up button twice and it shows "friday". Push the menu button again and "friday" is stored and the display shows the time. Keep pushing the menu button until it has finished storing all the time and date info. If the count up button is not pushed while cycling through the menu then the old data is just stored again. The last subroutine at the bottom is the sub that cycles through the menu.

This code is so long it has overloaded the forum limit for a post so posting it in several parts.
 

moxhamj

New Member
' pin6= latch clock HC595 pin 12 - low to high transition latches the data
' pin7 = serial data out = HC595 pin 14
' pin5= shift clock = HC595 pin 11 - low to high tranition stores the serial data out

' note **** in the picaxe programmer View menue Options/Mode screen, change the 16x gosub to 256x gosub
' if get weird bugs watch the maximum 4 nested gosubs

start: pause 1000
'gosub setclock
GoSub Initialiseclock ' tell i2c that clock exists
GoTo initnew ' start display



main: ' main program loop
'gosub testcount used for debugging the time set
GoSub buttontest
GoSub Readtime
GoSub SendData ' send to output pin 3 blue wire
GoSub firstline ' put display on 1st line
peek 92, b0
GoSub splitbyte ' hours
b1 = ":"
GoSub wrchar
peek 91, b0
GoSub splitbyte ' minutes
GoSub buttontest
b1 = 136 ' move cursor
GoSub wrins
peek 94, b0
GoSub splitbyte ' day
GoSub buttontest
b1 = "/"
GoSub wrchar
peek 95, b0
GoSub splitbyte ' month
GoSub buttontest
b1 = "/"
GoSub wrchar
peek 96, b0
GoSub splitbyte ' year
GoSub buttontest
' display weekday
GoSub Readtime
GoSub secondline
peek 93, b10 ' number 1 to 7, 1=sunday
Select Case b10
Case 1
For b9 = 0 To 8
lookup b9, ("Sunday "), b1
GoSub wrchar
Next
Case 2
For b9 = 0 To 8
lookup b9, ("Monday "), b1
GoSub wrchar
Next
Case 3
For b9 = 0 To 8
lookup b9, ("Tuesday "), b1
GoSub wrchar
Next
Case 4
For b9 = 0 To 8
lookup b9, ("Wednesday"), b1
GoSub wrchar
Next
Case 5
For b9 = 0 To 8
lookup b9, ("Thursday "), b1
GoSub wrchar
Next
Case 6
For b9 = 0 To 8
lookup b9, ("Friday "), b1
GoSub wrchar
Next
Case 7
For b9 = 0 To 8
lookup b9, ("Saturday "), b1
GoSub wrchar
Next
endselect
GoSub buttontest
GoSub OffPeakPower
' spend most of time waiting for button push
w0 = 0
Do
if pin1=1 then exit
pause 100
w0 = w0 + 1
if w0>500 then exit
Loop
GoSub buttontest
GoTo main

' **** latch routines ***


senddatatolatch: ' sends data in b0
b6 = b0 ' so returns b0 unchanged
' note QA is MSB and QH is LSB (binary number reads down) feed in LSB first
low 5
low 6
low 7
For b1 = 1 To 8
b2=b0 and %00000001
If b2 = 0 Then
low 7
Else
high 7
End If
high 5
low 5
Let b0 = b0 / 2
Next
high 6
low 6
b0 = b6
poke 87, b0 ' store the latch status
Return


QAhigh: peek 87, b0 ' pin 15
b0=b0 or %10000000
GoTo senddatatolatch

QAlow: peek 87, b0 ' pin 15
b0=b0 and %01111111
GoTo senddatatolatch

QBhigh: peek 87, b0 ' pin 1
b0=b0 or %01000000
GoTo senddatatolatch

QBlow: peek 87, b0 ' pin 1
b0=b0 and %10111111
GoTo senddatatolatch

QChigh: peek 87, b0 ' pin 2
b0=b0 or %00100000
GoTo senddatatolatch

QClow: peek 87, b0 ' pin 2
b0=b0 and %11011111
GoTo senddatatolatch

QDhigh: peek 87, b0 ' pin 3
b0=b0 or %00010000
GoTo senddatatolatch

QDlow: peek 87, b0 ' pin 3
b0=b0 and %11101111
GoTo senddatatolatch

QEhigh: peek 87, b0 ' pin 4
b0=b0 or %00001000
GoTo senddatatolatch

QElow: peek 87, b0 ' pin 4
b0=b0 and %11110111
GoTo senddatatolatch

QFhigh: peek 87, b0 ' pin 5
b0=b0 or %00000100
GoTo senddatatolatch

QFlow: peek 87, b0 ' pin 5
b0=b0 and %11111011
GoTo senddatatolatch

QGhigh: peek 87, b0 ' pin 6
b0=b0 or %00000010
GoTo senddatatolatch


QGlow: peek 87, b0 ' pin 6
b0=b0 and %11111101
GoTo senddatatolatch

QHhigh: peek 87, b0 ' pin 7
b0=b0 or %00000001
GoTo senddatatolatch

QHlow: peek 87, b0 ' pin 7
b0=b0 and %11111110
GoTo senddatatolatch

' *** clock routines ***

Readtime:
i2cslave %11010000, i2cslow, i2cbyte &#8216; set slave details
readi2c 0, (b0, b1, b2,b3,b4,b5,b6) &#8216; read sec, min, hour weekday day month year
poke 90, b0 ' secs
poke 91, b1 ' mins
poke 92, b2 ' hours
poke 93, b3 ' weekday 1-7
poke 94, b4 ' day
poke 95, b5 ' month
poke 96, b6 ' year
b13 = b0
GoSub BCDtoDecimal ' seconds
b0 = b13
b13 = b1
GoSub BCDtoDecimal ' mins
b1 = b13
b13 = b2
GoSub BCDtoDecimal ' hours
b2 = b13
b13 = b4
GoSub BCDtoDecimal ' day (no need to do weekday as <10)
b4 = b13
b13 = b5
GoSub BCDtoDecimal ' month
b5 = b13
b13 = b6
GoSub BCDtoDecimal
b6 = b13
poke 80, b0 ' poke decimal data for exporting to other picaxes if requested
poke 81, b1 ' mins
poke 82, b2 ' hour
poke 83, b3 ' day 1-7
poke 84, b4 ' day
poke 85, b5 ' month
poke 86, b6 ' year
Return

Setclock:i2cslave %11010000, i2cslow, i2cbyte
' seconds minutes hours weekday day month year
' sunday = 1 and this was set on Wed = 4
' day of the week number is not linked - it just goes to 7 then resets
' see codes re 24/12 hour clock but essentially if send as the hex number is 24h clock
' *** warning if ever set clock use 2 bcd numbers not decimal value
writei2c 0, ($00, $32, $13, $01, $05, $08, $07, $10)
Return

WriteClock:i2cslave %11010000, i2cslow, i2cbyte' pokes last reads back into clock
peek 90, b0
peek 91, b1
peek 92, b2
peek 93, b3
peek 94, b4
peek 95, b5
peek 96, b6
writei2c 0,(b0,b1,b2,b3,b4,b5,b6,$10)
Return

Initialiseclock:i2cslave %11010000, i2cslow, i2cbyte
Return

BCDtoDecimal: ' all clock values are 2 bcd numbers. If convert to hex they display correctly
' pass b13, returns b13
b12=b13 and %00001111
b11 = b13 / 16 ' shifts right 4 places
b10 = b11 * 10
b13 = b10 + b12
Return


' ***** LCD routines ******

' pin7 for reved's direct comms = pin 14 on the display = QA
' pin6= display 13 = QB
' pin5 = display 12 = QC
' pin4 = display 11 = QD
' pin3 = display 6 = QE
' pin2 = display 4 = QF
' QG = led



initnew: b0 = 0
GoSub senddatatolatch ' all outputs low
pause 200
GoSub QChigh ' send 0011
GoSub QDhigh
GoSub toggleenable
pause 10
GoSub toggleenable
GoSub toggleenable
GoSub QDlow ' send 0010
GoSub toggleenable
GoSub toggleenable
GoSub QAhigh ' send 1000
GoSub QClow
GoSub toggleenable
b1=%00001110' 14
GoSub wrins
GoSub cleardisplay
GoSub hidecursor
GoSub firstline
GoTo main

cleardisplay: b1 = 1
GoSub wrins
Return

hidecursor: b1 = 12
GoSub wrins
Return

firstline: b1 = 128
GoSub wrins
Return

secondline: b1 = 192
GoSub wrins
Return
 

moxhamj

New Member
toggleenable: GoSub QEhigh
GoSub QElow
Return



splitbyte: ' takes b0 which consists of two bcd numbers from the time chip, splits into two ascii numbers and sends to display
poke 97, b0
b1=b0 and %11110000' msb first
b1 = b1 / 16 ' shift to right
b1 = b1 + 48 ' add so turns into numbers
GoSub wrchar ' write 1st number
peek 97, b0
b1=b0 and %00001111' lsb
b1 = b1 + 48
GoSub wrchar ' write 2nd number
peek 97, b0 ' restore for next sub so doesnt change
Return


wrchar: ' since the lcd is the only thing using the HC595 it doesn't matter what the previous bytes are
' to send a char, RS (QF) = high, SE (QE) toggles nibbles in
b8 = b1 ' temp store
low 5 ' setup HC595
low 6
low 7
b0=b1 and %11110000' mask high nibble
b0=b0 or %00000100' make RS high
b0=b0 or %00000010' make led high
GoSub fast595 ' set up bytes, will resend so nibble definitely high when send
b0=b0 or %00001000' toggle SE (QE)
GoSub fast595
b0=b0 and %11110100' SE low, and led off also
GoSub fast595
b0 = b8 * 16 ' move other nibble into b0
b0=b0 and %11110000' mask high nibble but probably not necessary
b0=b0 or %00000100' make RS high
GoSub fast595 ' set up bytes, will resend so nibble definitely high when send
b0=b0 or %00001000' toggle SE (QE)
GoSub fast595
b0=b0 and %11110100' SE low, and led off also
GoSub fast595
b1 = b8 ' return this character in case need to print again
Return

wrins: ' since the lcd is the only thing using the HC595 it doesn't matter what the previous bytes are
' to send a char, RS (QF) = low, SE (QE) toggles nibbles in
b8 = b1 ' temp store
low 5 ' setup HC595
low 6
low 7
b0=b1 and %11110000' mask high nibble and RS set low
GoSub fast595 ' set up bytes, will resend so nibble definitely high when send
b0=b0 or %00001000' toggle SE (QE)
GoSub fast595
b0=b0 and %11110000' SE low
GoSub fast595
b0 = b8 * 16 ' move other nibble into b0
b0=b0 and %11110000' mask high nibble but probably not necessary
GoSub fast595 ' set up bytes, will resend so nibble definitely high when send
b0=b0 or %00001000' toggle SE (QE)
GoSub fast595
b0=b0 and %11110000' SE low
GoSub fast595
b0=b0 or %00000100' RS high ready for next byte
GoSub fast595
Return



fast595: ' send byte in b0 out to HC595 QA=MSB
b3 = b0 ' temp store
For b1 = 1 To 8
b2=b0 and %00000001
If b2 = 0 Then
low 7 ' send out bit
Else
high 7
End If
high 5 ' toggle clock
low 5
Let b0 = b0 / 2 ' shift right
Next
high 6 ' send out byte
low 6
b0 = b3 ' return the byte unchanged in b0
Return



dualbcdtodecimal: ' takes b0=aaaabbbb = 2 bcd numbers and returns b0=actual number eg 00010001 then b1=11
b1=b0 and %11110000' mask high nibble
b2 = b1 / 16 ' move to right 4 places
b3 = b2 * 10 ' multiply by 10
b4=b0 and %00001111' mask low nibble
b0 = b3 + b4
Return

decimaltodualbcd: ' pass b0, does reverse of above
b1 = b0 / 10 ' get high nibble tens
b2 = b1 * 16 ' move to left 4 places
b3 = b1 * 10 ' multiply back
b4 = b0 - b3 ' get ones
b0 = b2 Or b4 ' merge together
Return

testcount: peek 98, b0

GoSub dualbcdtodecimal
b0 = b0 + 1
If b0 > 20 Then
b0 = 0
End If
GoSub decimaltodualbcd
poke 98, b0
b1 = 133
GoSub wrins ' cursor move
peek 98, b0 ' get back number
GoSub splitbyte ' display two numbers
Return


OffPeakPower: ' rules - 10pm to 8am= off peak EXCEPT november to march inclusive, = 9pm
' and also Sat and Sun=off peak
peek 82, b0 ' hour
peek 83, b1 ' weekday number
peek 85, b2 ' month
b3 = 0 ' 0=peak, 1 = off peak
Select Case b0 ' hour 24 hour clock off peak = 22 to 24 and 0 to 7
Case 22 To 24
b3 = 1
Case 0 To 7
b3 = 1
Else
b3 = 0 ' peak
endselect
Select Case b1
Case 1 ' Sunday
b3 = 1
Case 7 ' Saturday
b3 = 1
endselect
Select Case b2
Case 11 To 12
b3 = 1
Case 1 To 3
b3 = 1
endselect
' display
Select Case b3
Case 0
b1 = 201
GoSub wrins
For b9 = 0 To 6
lookup b9, (" Peak"), b1
GoSub wrchar
Next
high 0 ' set output pin 0 high
low 2
Case 1
b1 = 201
GoSub wrins
For b9 = 0 To 6
lookup b9, ("OffPeak"), b1
GoSub wrchar
Next
high 2 ' set output pin 2 high
low 0
endselect
Return

SendData: Let b2 = 0 ' device no 0
'let b3=15 ' 4 data bytes
peek 81, b3
peek 82, b4
peek 85, b5
peek 86, b6
Let w6 = b3 + b4 + b5 + b6 ' add up checksum
serout 3,N1200,("DataI",b2,b3,b4,b5,b6,b12,b13)
Return


enternewnumber: ' pass poke88=cursor position, poke89=max count returns b0= new number to store in 9x
peek 88, b1
GoSub wrins ' cursor to first item
b1 = " "
GoSub wrchar
GoSub wrchar
GoSub Readtime
Do
peek 88, b1
GoSub wrins ' cursor to this position
Let b0 = b9
GoSub decimaltodualbcd
GoSub splitbyte
peek 88, b1
GoSub wrins ' cycle number and blank so know this one is active
b1 = " "
GoSub wrchar
if pin1=1 then exit
If pin0 = 1 Then
' count up
Let b9 = b9 + 1
peek 89, b0
If b9 > b0 Then
b9 = 0
End If
End If
Loop
peek 88, b1
GoSub wrins ' display last number
b0 = b9
GoSub decimaltodualbcd ' new value in b0
GoSub splitbyte
Return



buttontest:
If pin1 = 0 Then
Return ' button not pushed
End If
' menu button pushed so cycle through
' set hours first
peek 82, b9 ' get decimal value
poke 88, 128 ' cursor position
poke 89, 24 ' maximum count
GoSub enternewnumber
poke 92, b0
GoSub WriteClock ' store new hours
' now change minutes
peek 81, b9
poke 88, 131
poke 89, 60
GoSub enternewnumber
poke 91, b0
GoSub WriteClock
' change date day number
peek 84, b9 ' current value
poke 88, 136 ' cursor
poke 89, 31 ' max count
GoSub enternewnumber
poke 94, b0 ' store
GoSub WriteClock
' change month
peek 85, b9 ' current value
poke 88, 139 ' cursor
poke 89, 12 ' max count
GoSub enternewnumber
poke 95, b0 ' store
GoSub WriteClock
' change year
b9 = 7 ' defaults back to 2007 otherwise take forever cycling to 99
poke 88, 142
poke 89, 99
GoSub enternewnumber
poke 96, b0 ' store
GoSub WriteClock
' change day number
peek 83, b9
poke 88, 192 ' second line now
poke 89, 7 ' max
GoSub enternewnumber
If b0 = 0 Then
b0 = 1
End If
poke 93, b0 ' store
GoSub WriteClock

' finish up
GoSub cleardisplay
b1 = 128
GoSub wrins
b1 = "S"
GoSub wrchar
b1 = "e"
GoSub wrchar
b1 = "t"
GoSub wrchar
pause 4000
GoTo main
 

jimmy88

New Member
thank you acula very much
but how about the lcd firmware is it possible to add it with the circuit to make the programming esier
 

moxhamj

New Member
Use the LCD code that is in manual 3. It is much simpler than the LCD routines I have in this code. Should also shorten the program. Build it up in modules and get each working before moving onto the next. Have you got the LCD to print "Hello World" yet?
 
Top