real time clock
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: real time clock

  1. #1
    maria's Avatar
    maria Guest

    Default real time clock

    Hi there,

    I'm using PIC BASIC with a PIC16F877. I'm wondering if there's anyone out there who could tell me how to connect a real time clock IC (the Dallas DS1302 is the one I have) to the PIC and get the PIC to display the time on an LCD? I have my LCD up and running so I wouldnt need too much detail on the LCD bit.

    Thanks!

    Best Wishes,
    Maria.

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

    Default

    Have a look at the RTC thread in ths section (set your display to show posts from the last 30 days or more).

    PS. Posts do get read by folks regardless what section you post them in... posting in multiple sections is unnescessary.

  3. #3

    Default

    Maria,

    You might want to try this code. This is how I control this chip. If you need help with it just ask and I'll see if I can provide you some assistance.

    '-------------------------- Clock Variables ---------------------------------

    rst var portb.2 ' DS1302 Reset Pin
    clk var portb.1 ' DS1302 Clock Pin
    dq var portb.0 ' DS1302 Data Pin

    '----------------------- Write Commands For DS1302 --------------------------

    writectrl con $8E ' Control byte
    writeram con $80 ' Write to RAM
    writeprotect con $00 ' Write-protect DS1302
    writesec con $80 ' Write seconds
    writemin con $82 ' Write minutes
    writehour con $84 ' Write hour
    writedate con $86 ' Write date
    writemonth con $88 ' Write month
    writeyear con $8C ' Write year

    '------------------------- Read Commands For DS1302 -------------------------

    readsec con $81 ' Read seconds from DS1302
    readmin con $83 ' Read minutes from DS1302
    readhour con $85 ' Read hours from DS1302
    readdate con $87 ' Read date from DS1302
    readyear con $8D ' Read year from DS1302
    readmonth con $89 ' Read month from DS1302

    '------------------------------ Time Variables ------------------------------

    mem var byte ' Temporary data holder
    outbyte var byte ' Second byte to ds1302
    reg_adr var byte ' First byte to DS1302
    date var byte ' Date variable
    ss var byte ' Seconds variable
    mm var byte ' Minutes varibale
    hh var byte ' Hours variable
    mo var byte ' Month variable
    yr var byte ' Year variable

    '------------------------ Initial Settings For Ports ------------------------

    low rst ' Set reset pin low
    low clk ' Set clock pin low

    trisb = 0
    trisa = 0

    '----------------------- Set Initial Time Variables -------------------------

    if portb.4 = 1 then START ' Set inital clock start up if jumper is present
    reg_adr = writectrl ' Set to control byte
    outbyte = writeprotect ' Set turn off protection
    gosub w_out ' Send both bytes
    reg_adr = writesec ' Set to write seconds register
    outbyte = $00 ' Set to write 00 to seconds register
    gosub w_out
    reg_adr = writemin
    outbyte = $30
    gosub w_out
    reg_adr = writehour
    outbyte = $00
    gosub w_out
    reg_adr = writedate
    outbyte = $01
    gosub w_out
    reg_adr = writemonth
    outbyte = $01
    gosub w_out
    reg_adr = writeyear
    outbyte = $00
    gosub w_out
    reg_adr = writectrl
    outbyte = writeprotect
    gosub w_out

    start:
    reg_adr = readsec ' Read seconds
    gosub w_in
    ss = mem
    reg_adr = readmin ' Read minutes
    gosub w_in
    mm = mem
    reg_adr = readhour ' Read Hours
    gosub w_in
    hh = mem
    reg_adr = readyear ' Read Year
    gosub w_in
    yr = mem
    reg_adr = readdate ' Read Date
    gosub w_in
    date = mem
    reg_adr = readmonth ' Read Month
    gosub w_in
    mo = mem
    lcdout $fe,1,"TIME:",HEX2 hh,":",HEX2 mm,":",HEX2 ss
    pause 500
    goto start

    '----------------------- Time Commands Subroutines --------------------------

    w_in:
    mem = reg_adr ' Set mem variable to reg_adr contents
    high rst ' Activate the DS1302
    shiftout dq,clk,0, [mem] ' Send control byte
    shiftin dq,clk,1, [mem] ' Retrieve data in from the DS1302
    low rst ' Deactivate DS1302
    return

    w_out:
    mem = reg_adr ' Set mem variable to reg_adr contents
    high rst ' Activate the DS1302
    shiftout dq,clk,0, [mem] ' Send control byte
    mem = outbyte ' Set mem variable to outbyte contents
    shiftout dq,clk,0, [mem] ' Send data stored in mem variable to DS1302
    low rst ' Deactivate DS1302
    return

  4. #4

    Default

    when i use this code, with a serout commando the compiler give a error on the code HEX2.

    And when i leave the HEX2 in the serout and replace them bij # the counting gives problems what does the hex2 does, and how can i display the time and date on a console pc with the serout command?

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762

    Default

    RTFM

    There is no HEX modifier with SEROUT, use SEROUT2 instead.

    see PBP Manual Section 5.73 & 5.74
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  6. #6

    Default

    already fix the problem use the and and shift >>4 function

  7. #7
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,046

    Default

    Hey CocaColaKid, thanx for the code it worked, however, I suggest an improvement as stated in the DS1302 datasheet U R supposed to read
    the seconds again at the end in case the second ticks over from 59 to
    00 while you were reading the mins, hrs, etc. this could result in erroneous
    Real Time reading.

    Suggest modification here:
    ss var byte 'seconds
    ss2 var byte 'seconds comparison byte

    start:
    reg_adr = readsec ' Read seconds
    gosub w_in
    ss = mem
    reg_adr = readmin ' Read minutes
    gosub w_in
    mm = mem
    reg_adr = readhour ' Read Hours
    gosub w_in
    hh = mem
    reg_adr = readyear ' Read Year
    gosub w_in
    yr = mem
    reg_adr = readdate ' Read Date
    gosub w_in
    date = mem
    reg_adr = readmonth ' Read Month
    gosub w_in
    mo = mem
    reg_adr = readsec ' Read seconds
    gosub w_in
    ss2 = mem
    IF ss <> ss2 THEN start 'COMPARE FIRST AND SECOND READINGS AND TRASH IF DIFFERENT.
    lcdout $fe,1,"TIME:",HEX2 hh,":",HEX2 mm,":",HEX2 ss
    pause 500
    goto start

    Cheers, Art.

  8. #8
    bahattinkor's Avatar
    bahattinkor Guest

    Smile Problem with DS1302 and Proton+

    dear friends,

    I have a problem with the DS1302, PIC16f877 and PIC Proton+ combination. I designed a basic circuit in PROTEUS, and put your code in it. I worked fine. There was no problem. but when I made that circuit real, I met with problems. When I powered the PIC I can not see the time runing. The only thing that I see is " 00:00:80" and it always stays same. I used portd.0,d1 and d2 in the connection of PIc and DS1302. I used 32.768khz crystal. And there is no any mistake in connections. How can I fix this problem ?
    And one more small question. How can I reset LCD ? in PicBasic PRo I used to written "Flags=0". In Proton+ what should I write instead of this ?

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    For info on Proton... www.picbasic.org/forum

    I doubt PROTON have this option or it's hidden somewhere in the Help file, or somewhere on the forum.

    BUT try
    Code:
    Print $fe,$28 
    Print $fe,$0c 
    Print $fe,1
    This should work
    Last edited by mister_e; - 27th July 2005 at 03:38.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    bot402's Avatar
    bot402 Guest

    Default

    You should know better than that Steve. The PROTON does everything the PBP does, and a whole lot more!

    To reset the LCD, simply use: -

    Dim BPF as Byte SYSTEM ' Bring the system variable into BASIC

    Clear BPF ' Force a reset on the LCD the next time it's used

    However, this is the wrong forum for the PROTON compiler. As long as your not using a pirated version of the compiler, you are welcome to use the dedicated PROTON forum

  11. #11
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    347

    Smile

    Hello bahattinkor,

    I had the same problem for 2 days using a DS1337. It displayed the default time and if I programmed a new starting time that would display but would continue from there. This was on a printed circuit board that was already working but had a little accident with a floating wire that went into the side of the power supply box and blew everything up! After replacing most of the parts the board worked for a few days then quit. I put new chips on the board again but to no gain. I put all of the same parts into a newer board and they worked fine. Went back to the old board and found no connection between one side of the crystal and the DS 1337.

    The moral of this story is triple check your connections and use a meter!

    BobK

  12. #12
    bahattinkor's Avatar
    bahattinkor Guest

    Unhappy Still not working

    yes, I checked connections. voltages are normal but when I measured the cyrstal of Ds1302 with ossiloscope, I did not see any frequency. The ossilator does not ossilates. then I change DS1302 and 32.768Khz cyrstal with new ones but they are still not working. Can it be related with the Vcc that I used. I use 5V for Vcc for DS1302. Or Should I use any resistor or capacitor plus for the DS1302.

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Probably your Clock Halt flag is set..... it's undetermined when you put power on the RTC. Just clear this bit and you'll see oscillation on your scope.
    The problem is the same on many RTC. See the secondes register for the CH bit.

    Many cheaper probe will screw the signal coming from an Crystal. Place it on 10X and this will help a bit in many case.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Cool RTC - DS1302 with User Interface

    Here is a modified version of the code posted by CocaColaKid above.

    In the code above, the clock can only be set during the programming of PIC.

    With the modification here, the user can set the time, date etc. at any given time.

    Advise/post any additions, recommendations, modifications etc if any.
    Attached Images Attached Images  
    Attached Files Attached Files

  15. #15
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Cool Shorther HEX convertion sub routine

    As members are asking;

    Attached is the updated version with more space.
    (HEX Conversion is shorter)

    ------------------------------------------------------
    Attached Files Attached Files
    Last edited by sayzer; - 24th February 2006 at 19:01.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  16. #16
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Exclamation

    Hey CocaColaKid,
    Your code for the DS1302 is really good and efficient...
    I got a few questions,
    how should i enable the trickle charge option ?
    and how should i clear or set the clock halt flag???

  17. #17
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default

    I am a neophyte at programming, but have been writing BASIC code for 40 years. This is how I would do the conversion:

    DECX VAR BYTE(59)
    A VAR BYTE
    B VAR BYTE
    C VAR BYTE

    FOR B = 0 TO 59
    FOR A = $0 TO $59
    IF C = B THEN DECX(C) = A
    C = C+1
    NEXT A

    NEXT B
    ' THIS ROUTINE GENERATES AN ARRAY WHERE
    ' DECX(0) = $0
    ' DECX (1) = $1
    ' ETC.
    I didn't do it correctly the first time, this is better.
    Last edited by Russ Kincaid; - 6th July 2006 at 02:31.

  18. #18
    blainecf's Avatar
    blainecf Guest

    Talking Straight-forward RTC bits conversion algorithm

    For all you old timers, here's an alternate way of calculating Human Date/Time from the RTC bits:

    (Also, because all info is read in one shot, there is less liklihood that the seconds won't match the minutes.)

    I2CREAD DPIN,CPIN,RTC,I2C_Adr_B,[Rd_seconds, rd_minutes, rd_hours, Rd_DOW, Rd_DAy, RD_month, Rd_Year] ' in bcd code

    Seconds = Rd_Seconds.0 + (Rd_Seconds.1 * 2) + (rd_seconds.2 * 4) + (rd_Seconds.3 * 8) + (rd_seconds.4 * 10) + (rd_seconds.5 * 20) + (Rd_Seconds.6 * 40)

    Minutes = Rd_Minutes.0 + (Rd_Minutes.1 * 2) + (rd_Minutes.2 * 4) + (rd_Minutes.3 * 8) + (rd_Minutes.4 * 10) + (rd_Minutes.5 * 20) + (Rd_Minutes.6 * 40)

    Hours = RD_Hours.0 + (Rd_hours.1 * 2) + (rd_hours.2 * 4) + (rd_hours.3 * 8) + (rd_hours.4 * 10)

    am_pm = rd_hours.5
    dow = rd_dow

    day = rd_day.0 + (rd_day.1 * 2) + (rd_day.2 * 4) + (rd_day.3 * 8) + (rd_day.4 * 10) + (rd_day.5 * 20)

    Month = rd_month.0 + (rd_month.1 * 2) + (rd_month.2 * 4) + (rd_month.3 * 8) + (rd_month.4 * 10)

    Year = rd_year.0 + (rd_year.1 * 2) + (rd_year.2 * 4) + (rd_year.3 * 8) + (rd_year.4 * 10) + (rd_year.5 * 20) + (rd_year.6 * 40) + (rd_year.7 * 80)

  19. #19
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    I suppose that might work. But it wouldn't be my first choice.

    Only 30 or 40 times the needed code.

    DT

  20. #20
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default How do I set the 12 hr mode for DS1302

    Hello,

    I added some code to Omer Yildiz's ds1302_LCD_setup.bas program that was modified from CocaColaKids original code example posted here & I added a timer and have a few questions if anyone could answer me.

    I have read the DS1302 datasheet but couldn't figure out how to get the clock to show in the 12 hour mode for am & pm time. According to the datasheet I have to set bit 7 of the hours register to a high (1) but I don't understand Omer's code to do that. Also can anyone here explain what this kind of look up table is all about?

    Quote from Omer's code.............................................. ...............
    Lets burn the eeprom for something useful. A kind of lookup table.
    eeprom 1,[31,28,31,30,31,30,31,31,30,31,30,31]

    I've included the program here if anyone wants to look at it, I'm sure its not very efficient but it works.

    These are the modifications below that I made to Omer's ds1302_LCD_setup.bas program. A possible application could be as a kitchen timer.

    I added visual Lcd screens that shows you what your setting when setting the calendar and the clock. I also programmed the menu led to be used as a visual flashing indicator that the alarm time has elapsed. I added an up-count timer that increments each time the second variable of the DS1302 increments. I also added another 2 push buttons and followed Omer's nice example of his 2 button set and increment push button routine for setting the Seconds, Minutes and Hours times for the alarm. On initial power up the up-count timer is disabled, once your finished setting the times for the alarm and press the Set_Alarm_Timer_Push_Button then the up-counter starts incrementing. When the
    set time equals the up-count time then the alarm buzzer sounds for approx 10 beeps then shuts off while the red led continues to flash until the Set_Timer_Push_Button is pressed to shut it off. Eventually I'll change it again to add more buttons, one for each of the Seconds, Minutes and Hours settings so the times can be set quicker but it works great as is.

    There is one thing I noticed after getting the timer set up to work, is that when the up-count timer starts after your finished setting the alarm times, its not always accurate to the second. Because, depending on the time when your finished setting your times and then when you return to start the up-count timer, it very seldom starts exactly on a second change and can be out by as much as 900 ms. If this is only used as a kitchen timer then its not a big deal but in a time critical application it could be.

    Thanks
    jessey
    Attached Files Attached Files

  21. #21
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Default

    Quote Originally Posted by jessey
    ... Also can anyone here explain what this kind of look up table is all about?
    Quote from Omer's code.............................................. ...............
    Lets burn the eeprom for something useful. A kind of lookup table.
    eeprom 1,[31,28,31,30,31,30,31,31,30,31,30,31]

    Hi jessey,

    Omer is me.

    That code was so old and just for an example. I have modified it several times afterwards.

    For the eeprom look up table, it works while the user is in setup menu. It is not used in any other place in the code.

    While the user is changing the day, the table matches the number of days for the stored month.

    If the year is one of those with 29 days, then the "EEPROM location 2" will be written by 29 so that when user gets into "changing the day" and if it is in February then the max days on LCD will be 29.

    Examples:
    If the month is 1 then LCD shows the max day as day31 then starts from day1.

    If the month is 2 then LCD shows the max day as day28 or day29 depending on the year and then starts from day1.

    .
    ..
    ...

    if the month is 11 then LCD shows the max day as day30 then starts from day1.

    etc...
    Last edited by sayzer; - 29th August 2006 at 09:02.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  22. #22
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default Do I have this right?

    Hi sayzer,

    Thanks for the explanation of your eeprom code.

    I went over the DS1302 data sheet again (actually many times) and I think I got it now, I'm hoping. I finally realized that you wrote your code for the reads and writes of the Registers in hex which threw me off. When I converted them over to binary for the hours then it made some sense. I set bit 7 and bit 5 in the binary number then converted them back to hex. I haven't tried it yet but I think this might work.

    for am 12 hr mode
    writehour = 00100011 = $C4
    readhour = 10100011 = $A3

    for pm 12 hr mode
    readhour = 10101011 = $AB
    writehour = 00101011 = $D4

    Do you think this will do it? If I have this part right then I don't think I'll have any problems converting over the rest of the code to display it with the am and pm.

    Thanks
    jessey

  23. #23
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Default

    Take a look at this.
    You should get nice ideas from Melanie's extreme (ly easy for her) work here.


    http://www.melabs.com/resources/samp...ted/MN1307.txt


    ------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  24. #24
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default Nothing but questions

    Hi sayzer,

    Thanks for sending me the link to Melanie's code.

    Yea its way over my head, I don't understand the BCD system at all. I checked out BCD on the net and it says it can be used to save RAM space which can result in using half the storage space as compared to storing the same value in hex. If I read and understood that correctly then it would make sense to use it. This is the site where I read that: http://www.danbbs.dk/~erikoest/bcd.htm#top its got links to a lot of useful stuff that you didn't want to know! But I guess its all relevant if you want to learn programming.

    This is the BCD code that I didn't understand when I first looked at Melanie's code:
    Code:
     ' Subroutine Converts back to BCD
     ' -------------------------------
      ' CounterA is the entry variable
      ' CounterB holds the converted BCD result on exit
    ConvertBCD:
     CounterB=CounterA DIG 1
     CounterB=CounterB<<4
     CounterB=CounterB+CounterA DIG 0
     Return
    It looks a little similar to this routine below that I found on the link that I posted above:
    Code:
    SUBROUTINE PACKIT
    On Entry: 
    
    Register B contain the upper byte of the BCD number. 
    Register C contains the lower byte of the BCD number. 
    
    On Exit: 
    
    Register A contains the Packed BCD Number. 
    
    To pack the number we must: 
    
    A <= (B) 
    Rotate A Left 4 times 
    A <= (A) + (C) 
    
    That's all. We could enhance our routine by checking to see if 
    the first number is zero. If it is, we do not need to rotate
    4 times.
    I have another question for you if you understand Melanie's ConvertBCD: subroutine above, what does the DIG 1 & DIG 0 do? I've seen it used in some of the code posted here on the forum but I don't understand what its function is?

    Oh, and another question, you didn't confirm or not if my last post was a correct way to set the hours registry?

    Thanks
    jessey

  25. #25
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Default

    Quote Originally Posted by jessey
    ....
    for am 12 hr mode
    writehour = 00100011 = $C4
    readhour = 10100011 = $A3

    for pm 12 hr mode
    readhour = 10101011 = $AB
    writehour = 00101011 = $D4
    hi jessey,

    When reading or writing you change the register address command.

    Reading: $85
    Writing : $84

    If you want to "Write Hour" to the chip, then you first send $84 command and prepare the chip to accept the incoming data for "hour". Then right after that you send your byte variable consisting your "hour data".

    If sending 12Hr AM mode then the Bit7 of your byte should be "0" indicating 12Hr mode, and Bit5 should be "1 " indicating "AM".

    Sending $85 command to the chip will be for "read hour" command and incoming data byte will consist of "hour data". Thus for reading, you do not set a byte to write to the chip; just read the incoming data.

    In this case, I need to correct your arrangement as below.

    12AM hr mode
    writehour = 00100011
    Bit7=0 12hr mode.
    Bit5=1 AM mode.
    Correct

    readhour = 10100011
    No need.
    Just send $85 and read the incoming data.


    12PM hr mode
    writehour = 00101011
    Bit7=0 12hr mode.
    bit5=1 AM mode.
    incorrect

    The correct byte arrangement:
    writehour = 00001011
    Bit7=0 12Hr mode.
    bit5=0 PM mode.


    readhour = 10101011
    No need.
    Just send $85 and read the incoming data.



    Quote Originally Posted by jessey
    I have another question for you if you understand Melanie's ConvertBCD: subroutine above, what does the DIG 1 & DIG 0 do?

    In a byte or word, the digits counts from right to left (just like Arabic).

    Say we have a byte and it is set to Decimal 245.

    ex:
    Test VAR BYTE
    Apple VAR BYTE

    Test = 245

    In this case, from right to left,
    Test Dig 0 is 5
    Test Dig 1 is 4
    Test Dig 2 is 2

    to extract any of these numbers and use in somewhere else, we use;

    Apple = Test Dig 1

    Apple is now 4.



    How is it now ?
    ---------------------
    Last edited by sayzer; - 1st September 2006 at 16:13.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  26. #26
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default seems simple enough?

    Hi sayzer,

    I can't seem to figure out what I'm doing wrong here. This is what I did to change to the 12 hour am & pm mode. I got rid of the "writehour CON $84" statement, as its not required anymore. Then I created these four con's and variable below:
    Code:
    Mode VAR BIT
    Mode = 0   ' starts in am mode on initial power-up
    writehour_am    con $C4
    writehour_pm    con $D0
    am CON 0
    pm CON 1
    Then in your setup: subroutine I added this code block to replace your code block for the hourx:
    Code:
            IF Mode = am THEN
              reg_adr = writehour_am   ' = 00100011
            ELSE
              reg_adr = writehour_pm   ' = 00001011
            ENDIF
            outbyte = hourx
            gosub w_out
    Then in your in your sethour: subroutine I added this code block to replace yours for setting the hour:
    Code:
            IF CHNG = 0 THEN        'change the hour on display
                pause 100
                hour = hour + 1
                IF hour > 12 THEN
                  IF Mode = am THEN
                     Mode = pm
                  ELSE
                     Mode = am
                  ENDIF
                     hour = 1
                ENDIF
              call send
            ENDIF
    And that's it. Seems simple enough but it won't work. After I finish setting the clock and return to the start: subroutine it shows two zero's instead of what I set it to. I added these modifications to your original code without my added timer counter routines to rule out any of the other changes I made to your code. I used a converter that is here: http://www.itlocation.com/en/softwar...,download,.htm to calculate the HEX values. Its a great converter because it allows copping and pasting the values into and out of the converter.

    I found a discrepancy in the manual for what you said about bit 7.

    You said:
    Code:
    If sending 12Hr AM mode then the Bit7 of your byte should be 
    "0" indicating 12Hr mode, and Bit5 should be "1 "
    indicating "AM".
    And the manual says:
    Code:
                            AM-PM/12-24 MODE 
    Bit 7 of the hours register is defined as the 12- or 24-hour 
    mode select bit. When high, the 12-hour mode is selected.
    In the 12-hour mode, bit 5 is the AM/PM bit with logic high 
    being PM.
    I changed the bits to what the manual says but still ended up with the same results. I'll keep plugging away at it to see if I can figure it out but in the meantime would you have any ideas on what I've done wrong here?

    Thanks
    jessey

  27. #27
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,230

    Default

    Quote Originally Posted by jessey

    Code:
    IF hour > 12 THEN
    
         IF Mode = am THEN
                    Mode = pm
         ELSE
                    Mode = am
         ENDIF
         
         hour = 1
    
    ENDIF
    Why don't you try this:

    Code:
    IF hour > 12 THEN
         TOGGLE Mode
         hour = 1
    ENDIF

    For the Bit7 and Bit5, I checked again, you are right. I apologize.

    Say your Bit7 and Bit5 are set correctly.
    The rest, Bit4,Bit3,Bit2,Bit1 and Bit0 are consisting your hour data (in AM mode). In PM mode, Bit5 is also consisting hour data.
    You are setting the hour data the same each time.
    Last edited by sayzer; - 4th September 2006 at 12:16.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  28. #28
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Question 32.768 Khz

    Is it possible to use a 32.768 Khz crystal with picbasic pro ?
    I know the minimum given in manual is 4 Mhz, but is there anyway to use a 32.768 Khz to reduce power consumption ? ? ?

  29. #29
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by shahidali55 View Post
    Is it possible to use a 32.768 Khz crystal with picbasic pro ?
    I know the minimum given in manual is 4 Mhz, but is there anyway to use a 32.768 Khz to reduce power consumption ? ? ?
    If you run a PIC at 32.768khz, with a PBP program that's compiled to run at 4Mhz, the only thing that'll happen is it'll run 122 times slower (i.e. pause 1 @ 4Mhz = pause 122 @ 32.768khz).

  30. #30
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Smile

    Quote Originally Posted by shahidali55 View Post
    I know the minimum given in manual is 4 Mhz
    Not that helps here, but 3 MHz also is an option as is given in the manual

    Code:
    Define OSC 3
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  31. #31
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Default

    I've already tried that skimask. . .
    It really puts all the PBP routines off . . .
    LCDOUT takes like 3 seconds to print 16 digits . .

  32. #32
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by shahidali55 View Post
    It really puts all the PBP routines off . . .
    LCDOUT takes like 3 seconds to print 16 digits . .
    Which is exactly what I'd expect...unless you write the code in assembly, PBP will time everything like it was running 4Mhz. Maybe try 'lcd_commandus' and lcd_dataus' both set to 1 and see if it works like that at 32khz.

    Which PIC are you using this time?
    There is a clock switching feature in most newer PICs these days, can switch between the main (4Mhz or whatever) and the internal 32/37/40khz (depends on the datasheet you're looking at) 'backup' oscillator if configured correctly. I use it all the time to save power.

  33. #33
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Default

    I'm using a 16F84A so there is no question of internal oscillator.
    I tried several other things besides LCDOUT. Even FOR and WHILE statements take a lot o ftime to execute . . .
    I used a external 32.768Khz oscillator.
    Just to verify that the F84 was running at 32.768Khz, i tried a clock code on it and it does keep accurate time . . . down to a second a day.

  34. #34
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by shahidali55 View Post
    I'm using a 16F84A so there is no question of internal oscillator. I tried several other things besides LCDOUT. Even FOR and WHILE statements take a lot o ftime to execute . . . I used a external 32.768Khz oscillator. Just to verify that the F84 was running at 32.768Khz, i tried a clock code on it and it does keep accurate time . . . down to a second a day.
    If you're running 32.768khz, everything is going to take a lot longer to execute.
    The clock is 32.768khz, but the PIC is only executing instructions at 8.192khz (Fosc/4), and if you're code has a lot of call's, gosub's, returns, anything that takes the code to 'somewhere else', it'll run half that fast again (4.096khz, Fosc/4 + one extra instruction for each 'somewhere else').

    So, what are you asking? What's the point?
    Last edited by skimask; - 31st May 2007 at 16:12.

  35. #35
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Default

    I think i'll stick to 4Mhz for now . . .

  36. #36

    Unhappy enabling trickle charging

    this is a very belated response to shahidali55.

    I've added a tiny bit of code to "ds1302_user_interface.txt" to enable trickle charging. This is a small feat, but helped me understand how the register addressing and definitions are used.

    edit: I'm using a 5v 0.47f supercap which doesn't need diodes or resistors, so "trickledef" below uses a bit sequence 1010 (for TCS) 00 (for DS) and 00 (for RS), see page 7 of the DS1302 datasheet for other options

    cheers,
    Tobie

    ==========================

    'additional variables
    writechrg var byte
    tricklereg var byte
    writechrg = $91 'Write Command for the trickle register
    trickledef = $A0 'definition for a supercap which uses no diodes or resistors

    ' this goes in the "setup" subroutine, not as the statement first or last though
    reg_adr = writechrg
    outbyte = tricklereg
    gosub w_out
    Last edited by Tobie@mac.com; - 6th September 2007 at 16:50.

  37. #37

    Default Supercap

    hi,

    here's a modified version with trickle charge enabled for a supercap. Note this includes no LCD interface.

    A schematic is included in this pdf http://www.parallax.com/dl/appnt/jav2/appnote2.pdf

    Here's a datasheet for the supercap, I used the 0.47f component: http://rocky.digikey.com/WebLib/Coop...capacitors.pdf
    Attached Files Attached Files

  38. #38
    Join Date
    Jan 2007
    Posts
    3

    Question Alarm Time Problem

    Hi Melanie,

    I used your code MN1307.txt which is very good coded and easy to understand. I just want to add some alarm time. I know and did with some if...then...endif way.

    Now simply it works on alarm set time but output (portb.7) blinks and do not High permanently. I tried to find some solution but it is very simple that there should not be any problem with if...then...endif. But I think it is somethink with hardware related.

    Please help me in this regard because I must need this Alarm Clock. Thanks in anticipation.

    Best Regards,

    Shahzad

  39. #39
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136

    Thumbs up

    Thanks for the trickle charge routines Tobie . . .

  40. #40
    engrehaf's Avatar
    engrehaf Guest

    Default Re: real time clock

    hey guys i am a new member here
    i want some help in this topic if you can help

    HEX2 !! what it is ?
    because i use this sample code for 7 segment display, but i cannot deal with these variable like HEX2 hourx, HEX2 minutex and HEX2 seconds ???

    and thank you

Similar Threads

  1. Real Time Clock
    By in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd June 2012, 04:52
  2. real time clock - PCF8583
    By maria in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th April 2010, 15:41
  3. Real time clock ICs
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 66
    Last Post: - 20th October 2008, 16:05
  4. Real Time Clock
    By savnik in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th December 2006, 02:02
  5. Real time clock... what a headache!
    By Eng4444 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 8th June 2006, 21:56

Members who have read this thread : 8

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