real time clock


Closed Thread
Results 1 to 40 of 45

Thread: real time clock

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    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 17:13.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    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 13:16.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

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

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    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).

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


    Did you find this post helpful? Yes | No

    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
    __________________

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


    Did you find this post helpful? Yes | No

    Default

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

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    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.

Similar Threads

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

Members who have read this thread : 4

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