1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC Digital Clock

Discussion in 'Microcontrollers' started by muralibhat, Feb 11, 2007.

  1. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    No, you shouldn't have to 'HALT' it, must be something else. How are you writing, can you post a short snippet of the code you are using?
     
  2. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    Hi here is the routine I use
    RTC_brst_Wr movlw b'00101000' ; Select I2C master mode
    banksel SSPCON
    movwf SSPCON
    movlw I2CRATE ; Set the bus speed
    banksel SSPADD
    movwf SSPADD
    movlw b'00000000' ; And clear any status flags
    banksel SSPSTAT
    movwf SSPSTAT
    call I2CStop ; Ensure the bus is free

    ;write to ds 1307 with user values
    call I2CStart ; Take control of the I2C bus
    movlw DS1307|I2C_WR
    call I2CWrite ; Send the RTC write command
    movlw h'00'
    call I2CWrite ; And the register index
    call I2CRestart ; Then restart the I2C bus
    movf SECS, W
    call I2CWrite
    movf MINS, W
    call I2CWrite
    movf HRS, W
    call I2CWrite
    movf DOW, W
    call I2CWrite
    movf DAYS, W
    call I2CWrite
    movf MON, W
    call I2CWrite
    movf YRS, W
    call I2CWrite
    call I2CAck
    call I2CStop

    return
     
  3. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    Well, any change?
    I've looked over what you posted, and as far as I can see, there aren't problems, but then..
    What values are you ORing together (DS1307|I2C_WR) to send as the write command? Is your slave address DS1307 and the write command I2C_WR?

    According to Dallas' app note http://www.maxim-ic.com/appnotes.cfm/an_pk/3921
    they don't do the nak near the end of your loop.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0

    Hello I found the problem.I was using 4.7KOhms resistor as pullup for SDA and SCL. When I changed it to 10kOhms it started working finely. But Now I am facing another problem i.e. I have used the tutorial6.6 but I cannot read the keys. I am using the same port for I2C and keys i.e. Port C.Kindly anyone give me the source code for reading the 4 keys.
     
  6. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    Hello,
    As far as reading the key is concernerned i can blink the cursor and increment takes place only once. No other keys i.e. decrement and the next character keys doesn't work. If I remove the increment ket connection then decrement key decrements for one step only. I doubt there is some error in initialisation but I cannot figure out. Please help. I am using 16f877a and I teried the PORTA, PORTB--- result same.I develop using developement board.
     
  7. amiralsterr

    amiralsterr New Member

    Joined:
    Mar 16, 2007
    Messages:
    1
    Likes:
    0
    ok very thanks
     
  8. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia
    The datasheet says to use 4.7K doesnt it?
     
  9. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    Hello I am struggling with keypad routine. Key value floats and even if I do not press the key the value is detected and values are written. Please Help.
     
  10. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    Sounds like noise on the lines, which you are reading as keypresses; look up(google) key debounce, or switch debounce and you'll get tons of info. You can do it with hardware, or in software. You are using a micro, so software debounce is probably your best bet.
     
  11. pasanlaksiri

    pasanlaksiri Member

    Joined:
    Aug 28, 2006
    Messages:
    328
    Likes:
    4
    Location:
    Sri Lanka
  12. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    Hello I am back
    I have almost finished my project. But I am stuck in editing the time i.e to write user defined values to DS1307. Whenevr I write the values after the input from keys it displays erroneous time. I use indirect addressing mode for updating the time registers and aftre finishing editing I write the values to DS 1307
    Please Help
     
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,218
    Likes:
    640
    Location:
    Derbyshire, UK
    Are you converting the values from what you're using on the PIC, to the format required on the DS1307? - assuming the DS1307 uses a different format, as clock chips tend to.
     
  14. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    The values are not converted. If I write the predefined values, by making a subroutine, the clock gets updated but if only I use the values defined from the keys the clock does't get updated to the new values. I think the problem is in the indirect addressing. Is it nessasary to reset the PSR to the begining of the register array.
    Thank You
     
  15. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,218
    Likes:
    640
    Location:
    Derbyshire, UK
    You shouldn't ever assume anything, if you're not specifically setting the index value, how do you know what it is?, and where it might be pointing?.
     
  16. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    problem in writing to RTC

    Thank You, I have set the pointer to the location before I set the time buf registers but after setting the registers I am unable to write it to the RTC i.e this problem is arising only if I enter the subrouine to set the keys. I wrote a seperate subroutine to set the clock with specific data For example
    movlw h'12'
    movwf HRS and so on.I modified your toutorials 6.1 with interrupt to read the keys
    Kindly Help
     
  17. muralibhat

    muralibhat New Member

    Joined:
    Dec 25, 2006
    Messages:
    22
    Likes:
    0
    I Did It. I was making mistake by not selecting the proper memory bank. When I used the banksel my problem got solved and my clock is working. Now I have to work out for swiching on the pumpset when the power is back and switching it off after a set time etc.
    Thanks for everyone co-operated
     
  18. kg4zuz

    kg4zuz New Member

    Joined:
    Nov 16, 2007
    Messages:
    2
    Likes:
    0
    Why not go to this web site and look under downloads, then JULY 2001, you find there a perfect PIC16F84A digital alarm clock that works very well, also easy to build
     

Share This Page