Set the starting time with ds1302 picbasic


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2008
    Posts
    7

    Default Set the starting time with ds1302 picbasic

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by crisxstyle View Post
    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...

  3. #3
    Join Date
    Sep 2008
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by crisxstyle View Post
    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...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

  6. #6
    Join Date
    Sep 2008
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Sep 2008
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    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!

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    That doesn't look like PicBasicPro to me...

    Code:
    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,rtcyear,0]
    Maybe you should try the correct forums...

  9. #9
    Join Date
    Sep 2008
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    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!!!

  10. #10
    Join Date
    Sep 2008
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. RC Servo decoding/encoding using 12F683
    By ScaleRobotics in forum Code Examples
    Replies: 13
    Last Post: - 14th September 2010, 00:49
  2. INT2 anomaly in DT_INTS-18??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2010, 20:07
  3. DS1302 16F628 Woes
    By idtat in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2009, 14:15
  4. Working with indivividual bytes of an array
    By J_norrie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd January 2007, 19:16
  5. How to set external clock source in PBP
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 19th February 2005, 15:56

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts