PDA

View Full Version : Set the starting time with ds1302 picbasic



crisxstyle
- 29th September 2008, 16:02
Hi to all!!!

I'm just having some trouble with my program code!i'm making a simple project and i want to put on it a time clock!!easier!!!

BUT i cannot tell to the rtc ds1302 the starting time, if i do it with a constant like: rtchr=$00 it works but if i make a subroutine that with a button decide the value of hours and minutes than nothing work, it semms like the pic having some problems with hex and bcd!!

some one have a subroutine tha can help me!?!?!

thank you so much!!

bye bye Cris

skimask
- 29th September 2008, 17:06
Hi to all!!!

I'm just having some trouble with my program code!i'm making a simple project and i want to put on it a time clock!!easier!!!

BUT i cannot tell to the rtc ds1302 the starting time, if i do it with a constant like: rtchr=$00 it works but if i make a subroutine that with a button decide the value of hours and minutes than nothing work, it semms like the pic having some problems with hex and bcd!!

some one have a subroutine tha can help me!?!?!

thank you so much!!

bye bye Cris

Well, which one is it? the DS1307 or DS1302? DS1307 in the other thread...
And again...30 hits on the search...
And again...surely one of those has some good tips...

crisxstyle
- 29th September 2008, 18:02
hi and thank you for the fast answer!!

i've already searched but i cannot find the solution of my problem!!

can you help me please!?!

ds1302 or ds 1307 doesn't matter!!

byee

skimask
- 29th September 2008, 18:09
hi and thank you for the fast answer!!
i've already searched but i cannot find the solution of my problem!!
can you help me please!?!
ds1302 or ds 1307 doesn't matter!!
byee

Tell ya what...Let's see what code you have so far...

Melanie
- 29th September 2008, 18:23
http://www.melabs.com/resources/samples/submitted/MN1307.txt

Enjoy!

crisxstyle
- 29th September 2008, 18:40
thanks to skimask and melanie..now i'm printing the code to find the solution of my problem!i'll write for some news thank you so much!!!

byee

crisxstyle
- 30th September 2008, 12:22
http://www.melabs.com/resources/samples/submitted/MN1307.txt

Enjoy!

Hi!!I've read your program!!

But i'm searching somethink more simple, i'll try to explain:

' Allocate variables
Dim rtcyear as byte
Dim rtcday as byte
Dim rtcmonth as byte
Dim rtcdate as byte
Dim rtchr as byte
Dim rtcmin as byte
Dim rtchr1 as byte
Dim rtcmin1 as byte
Dim rtcsec as byte
Dim rtccontrol as byte
dim b0 as byte
dim b1 as byte
'-------------------------------------------------------------------------------
Low RST ' Reset RTC
Low SCLK
ADCON1 = 7 ' PORTA and E digital
Low PORTE.2 ' LCD R/W low = write
Delayms 100 ' Wait for LCD to startup

' Set initial time to 8:00:00AM 07/16/99
rtcyear = $99
rtcday = $06
rtcmonth = $07
rtcdate = $16
'rtchr = 0
'rtcmin = 0
'rtchr1 = 0
'rtcmin1 = 0
rtcsec = 0
if portb.1=1 then goto impostime
Gosub settime ' Set the time
Goto mainloop ' Skip subroutines
'-------------------------------------------------------------------------------
' Subroutine to set time
impostime:
if portb.1=0 then return else
pause 20
b0=0
button portb.2,1,255,255,b0,1,settore
pause 20
b1=0
button portb.3,1,255,255,b1,1,settminuti
pause 20
print at 3,1, dec2 rtchr, ";", dec2 rtcmin

goto impostime

settminuti:
pause 20
rtchr1=rtchr1+1
if rtchr1 =24 then rtchr1=0 else endif

rtchr=rtchr1

goto impostime

settore:
pause 20
rtcmin1=rtcmin1+1
if rtcmin1=60 then rtcmin1=0 else endif

rtcmin=rtcmin1

goto impostime


'--------------------------------------------------------------------------------

' Subroutine to write time to RTC
Settime:
RST = 1 ' Ready for transfer
Shout IO,SCLK,LSBFIRST,[$8e,0] ' Enable write
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
Shout IO,SCLK,LSBFIRST,[$be,rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rt cyear,0]
RST = 0 ' Reset RTC
Return


This program doesn't work because if i used the two buttons to set the initial time all works till i'm under "9", for example if i want to set hour=10 then i will read "A" in the display!

But if i don't use the buttons to select the initial time, and i write rtchour=$10 then i will read "10" on the display!

Who can tell me were is the mistake?!?!

i have to make a conversion before writing on the ds?!

help me please!

skimask
- 30th September 2008, 13:34
That doesn't look like PicBasicPro to me...



Dim rtcyear as byte
Dim rtcday as byte
Dim rtcmonth as byte
Dim rtcdate as byte
Dim rtchr as byte
Dim rtcmin as byte
Dim rtchr1 as byte
Dim rtcmin1 as byte
Dim rtcsec as byte
Dim rtccontrol as byte
dim b0 as byte
dim b1 as byte
Delayms 100 ' Wait for LCD to startup
print at 3,1, dec2 rtchr, ";", dec2 rtcmin
Shout IO,SCLK,LSBFIRST,[$8e,0] ' Enable write
Shout IO,SCLK,LSBFIRST,[$be,rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rt cyear,0]

Maybe you should try the correct forums...

crisxstyle
- 30th September 2008, 14:24
ohh...its basic plus but doesn't change so much!!!the program logic is the same..so....if you aren't able to make that simple conversione...doesn't matter!!!

crisxstyle
- 30th September 2008, 15:14
thank you so much guys but i've solved!!! i've created a special routine that convert data and send it to ds!!

than if you want you can close!!!


bye bye see ya