Real time clock ICs


Closed Thread
Results 1 to 40 of 67

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hello again Eng4444,

    It's nice to see that you are still here. Just to give a further example of what we are all trying to say to you, I just put the program that Melanie had just posted into an older project board of mine. Her program puts the LCD on PortB. Well my LCD is on PortA. So I made some minor changes to the program and tried it. It didn't work! Her program is for a 16F628 and I had a 16F872. I commented out the DEVICE setup and chose to set the configuration fuses through my programmer. Still didn't work. I only got blocks on line 1 of the LCD. So I opened the datasheet on the 16F872 and went to the section on the A/D module and found in the register explanation how to disable the A/D module and how to make the Analog pins all digital. Programmed the chip again and now the message scrolls across the screen!

    Now before you go and say what a smart ass you are let me explain that I do not have any degree in ANYTHING' I am a self employed alarm installer. I play with electronics for fun and once in a while I might make a few bucks making something to get the job done.

    I read this forum faithfully and pay attention to what the real pros like Melanie, Mister E, David Taylor, and the many other fine folks have to say when they offer their advise and expertise to someone. I really haven't gotten involved with anyone here to the extent that I have with you because I don't want to say or do something stupid. I don't think that you gave anyone here that has responded to you a fare shake. You say I dropped out. Well I didn't. I was reading everything. I read this forum at least twice a day and if I'm at a place that has internet access then I use my Dell handheld and go on to see what's up. If it wasn't for this forum and the fine people here I wouldn't have the knowledge I have today.

    By the way, I started at 7:15 this morning working on that little display program and was up and running including the troubleshooting in less than 1/2 hour. I keep the datasheets for the parts I use on my computer so that they are handy. The most frequently posted comment is read the datasheet. You don't have to read it like a novel, just refer to it once in a while. I know you are pressed for time so I won't hold you up. Good luck on you project! I have to goto work.

    Have a nice day!

    BobK
    Last edited by BobK; - 7th June 2006 at 13:02.

  2. #2
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Lightbulb Once again..

    i would say and repeat to you people:

    I DO NOT WORK WITH THIS TYPE OF TECHNOLOGY!!

    why no one understands??? i work with MEMS!!!!!!!! i already said it.....

    stop talking to me as if i'm a stupid intruder... you have your world and i have mine.. you are EXPERTS in PICs (this is why i came to you).

    and i am EXPERT in MEMS! ( in case someone needs anything related to MEMS i'll be ready!)

    Bobk, i checked your profile. I respect you very much but you made me nervous when you kept asking me to give details and schematics! So, i'm sorry to talk in a bad way to you.

    So here it is... a chematic! i did it with paint because with circuit builder it exceeds the attachement size. Those are the exact connections i did on Breadboard and then on PCB.

    And also, here is the program i used ( the same of Melanie):

    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628A, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628A, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628A, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628A, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628A, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628A, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE pic16F628A, PROTECT_OFF


    Define LCD_DREG PORTA ' Port for LCD Data
    Define LCD_DBIT 0 ' Use lower 4 bits of Port
    Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 6 ' Port Pin for RS bit
    Define LCD_EREG PORTA ' Port for Enable (E) bit
    Define LCD_EBIT 7 ' Port Pin for E bit
    Define LCB_BITS 4 ' Using 4-bit bus
    Define LCD_LINES 2 ' Using 2 line Display
    Define LCD_COMMANDUS 2000 ' Command Delay (uS)
    Define LCD_DATAUS 50 ' Data Delay (uS)


    SQWpin var PORTB.0
    SCLpin var PORTB.1
    SDApin var PORTB.2

    DecButton var PORTB.4
    SetButton var PORTB.5
    IncButton var PORTB.6

    Data @0,74,97,110,70,101,98,77,97,114,65,112,114
    ' Jan Feb Mar Apr
    Data 77,97,121,74,117,110,74,117,108,65,117,103
    ' May Jun Jul Aug
    Data 83,101,112,79,99,116,78,111,118,68,101,99
    ' Sep Oct Nov Dec
    Data 84,117,101,87,101,100,84,104,117,70,114,105
    ' Tue Wed Thu Fri
    Data 83,97,116,83,117,110,77,111,110
    ' Sat Sun Mon

    CounterA var byte
    CounterB var byte
    CounterC var byte
    CounterD var byte
    RTCSec var byte
    RTCMin var byte
    RTCHour var byte
    RTCWDay var byte
    RTCDay var byte
    RTCMonth var byte
    RTCYear var byte
    RTCCtrl var byte
    SetTime var byte
    SetSec var byte
    SetMin var byte
    SetHour var byte
    SetDay var byte
    SetMonth var byte
    SetYear var byte
    TimeOut var word

    ButtonRepeat con 200
    goto JumpStart

    ConvertBCD:
    CounterB=CounterA DIG 1
    CounterB=CounterB<<4
    CounterB=CounterB+CounterA DIG 0
    Return

    DisplayMonth:
    CounterB=CounterB*3-3
    DisplaySequence:
    For CounterA=CounterB to CounterB+2

    Read CounterA,CounterD
    LCDOut CounterD
    Next CounterA
    Return

    FindDays:
    LookUp SetMonth-1,[31,28,31,30,31,30,31,31,30,31,30,31],CounterA
    ' Above line gives the 'usual' days of the Month
    ' Section below adjusts for Leap-Year
    If SetMonth=2 then
    If (SetYear&$03)=0 then CounterA=29
    endif
    Return

    SetButtonRelease:
    LCDOut $FE,1
    While SetButton=0:Wend
    Pause 250 ' Small pause to kill any Key-Bounce
    Return

    JumpStart:
    CMCON=%00000111
    TRISA=%00000000
    TRISB=%11111111
    OPTION_REG.7=0
    Pause 200

    ReDisplay:
    LCDOut $FE,1
    ReDisplayLoop:

    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl]

    If RTCSec.7=1 then goto SetUpPreset

    If SetButton=0 then
    Gosub SetButtonRelease
    goto Setup
    endif

    LCDOut $FE,$80
    If RTCHour.6=1 then

    CounterA=(RTCHour>>4)&$01
    else
    CounterA=(RTCHour>>4)&$03
    endif
    CounterA=CounterA*10+(RTCHour&$0F)
    If RTCHour.6=1 then

    LCDOut #CounterA
    else
    LCDOut #CounterA Dig 1,#CounterA Dig 0
    endif
    LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    IF RTCHour.6=1 then
    If RTCHour.5=1 then
    LCDOut "PM"
    else
    LCDOut "AM"
    endif
    endif

    LCDOut " ",$FE,$C0
    CounterB=RTCWDay*3+33
    Gosub DisplaySequence

    LCDOut " ",#(RTCDay>>4)&$0F,#RTCDay&$0F," "
    CounterB=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
    Gosub DisplayMonth
    LCDOut " 20",#(RTCYear>>4)&$0F,#RTCYear&$0F,$FE,$80
    '
    Pause 250
    Goto ReDisplayLoop

    SetupPreset:
    RTCSec=$00
    RTCMin=$15
    RTCHour=$13
    RTCWDay=$01
    RTCDay=$12
    RTCMonth=$06
    RTCYear=$02
    RTCCtrl=$10

    Setup:
    SetTime=RTCHour.6
    If SetTime=1 then

    SetHour=(RTCHour>>4)&$01

    else
    SetHour=(RTCHour>>4)&$03

    endif
    SetHour=SetHour*10+(RTCHour&$0F)
    If SetTime=1 then
    If RTCHour.5=1 then
    If SetHour<12 then SetHour=SetHour+12

    else
    If SetHour=12 then SetHour=0
    endif
    endif
    SetMin=((RTCMin>>4)&$0F)*10+(RTCMin&$0F)
    SetSec=((RTCSec>>4)&$0F)*10+(RTCSec&$0F)
    SetYear=((RTCYear>>4)&$0F)*10+(RTCYear&$0F)
    SetMonth=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
    SetDay=((RTCDay>>4)&$0F)*10+(RTCDay&$0F)

    CounterC=0
    TimeOut=0
    SetupLoop:
    LCDOut $FE,1,"Set "

    If CounterC=0 then
    LCDOut "Mode"
    endif
    If CounterC=1 then
    LCDOut "Hours"
    endif
    If CounterC=2 then
    LCDOut "Minutes"
    endif
    If CounterC=3 then
    LCDOut "Seconds"
    endif
    If CounterC=4 then
    LCDOut "Year : 20"
    endif
    If CounterC=5 then
    LCDOut "Month"
    endif
    If CounterC=6 then
    LCDOut "Day"
    endif
    If CounterC<>4 then LCDOut " :"

    SetupDisplayLoop:
    If CounterC=0 then
    LCDOut $FE,$8B
    If SetTime=0 then
    LCDOut "24HR"
    else
    LCDOut "12HR"
    endif
    LCDOut $FE,$8B
    endif
    If CounterC=1 then
    CounterA=SetHour
    If SetTime=1 then
    LCDOut $FE,$8E
    ' Display AM/PM bit
    If CounterA<12 then
    LCDOut "AM"
    else
    LCDOut "PM"
    endif
    If CounterA=0 then CounterA=12
    If CounterA>12 then CounterA=CounterA-12
    endif
    LCDOut $FE,$8C,#CounterA
    If CounterA<10 then LCDOut " "
    LCDOut $FE,$8C
    endif

    If CounterC=2 then
    LCDOut $FE,$8E,#SetMin
    If SetMin<10 then LCDOut " "
    LCDOut $FE,$8E
    endif

    If CounterC=3 then
    LCDOut $FE,$8E,#SetSec
    If SetSec<10 then LCDOut " "
    LCDOut $FE,$8E
    endif

    If CounterC=4 then
    LCDOut $FE,$8D,#SetYear DIG 1,#SetYear Dig 0
    LCDOut $FE,$8D
    endif

    If CounterC=5 then
    LCDOut $FE,$8C
    CounterB=SetMonth
    Gosub DisplayMonth
    LCDOut $FE,$8C
    endif
    '
    ' Day
    ' ---
    If CounterC=6 then
    LCDOut $FE,$8A,#SetDay
    If SetDay<10 then LCDOut " "
    LCDOut $FE,$8A
    endif

    SetupEntryLoop:

    If DecButton=0 then

    If CounterC=0 then
    If SetTime=0 then
    SetTime=1
    else
    SetTime=0
    endif
    endif
    '
    ' Decrement Hours
    ' ---------------
    If CounterC=1 then
    If SetHour=0 then
    SetHour=23
    else
    SetHour=SetHour-1
    endif
    endif
    '
    ' Decrement Minutes
    ' -----------------
    If CounterC=2 then
    If SetMin=0 then
    SetMin=59
    else
    SetMin=SetMin-1
    endif
    endif
    '
    ' Decrement Seconds
    ' -----------------
    If CounterC=3 then
    If SetSec=0 then
    SetSec=59
    else
    SetSec=SetSec-1
    endif
    endif
    '
    ' Decrement Years
    ' ---------------
    If CounterC=4 then
    If SetYear=0 then
    SetYear=99
    else
    SetYear=SetYear-1
    endif
    endif
    '
    ' Decrement Month
    ' ---------------
    If CounterC=5 then
    If SetMonth=1 then
    SetMonth=12
    else
    SetMonth=SetMonth-1
    endif
    Gosub FindDays
    If SetDay>CounterA then SetDay=CounterA
    endif
    '
    ' Decrement Days
    ' --------------
    If CounterC=6 then
    Gosub FindDays
    If SetDay=1 then
    SetDay=CounterA
    else
    SetDay=SetDay-1
    endif
    endif
    Pause ButtonRepeat
    TimeOut=0
    Goto SetUpDisplayLoop
    endif

    If IncButton=0 then

    If CounterC=0 then
    If SetTime=1 then
    SetTime=0
    else
    SetTime=1
    endif
    endif
    '
    ' Increment Hours
    ' ---------------
    If CounterC=1 then
    If SetHour=23 then
    SetHour=0
    else
    SetHour=SetHour+1
    endif
    endif
    '
    ' Increment Minutes
    ' -----------------
    If CounterC=2 then
    If SetMin=59 then
    SetMin=0
    else
    SetMin=SetMin+1
    endif
    endif

    If CounterC=3 then
    If SetSec=59 then
    SetSec=0
    else
    SetSec=SetSec+1
    endif
    endif
    '
    ' Increment Years
    ' ---------------
    If CounterC=4 then
    If SetYear=99 then
    SetYear=0
    else
    SetYear=SetYear+1
    endif
    endif
    '
    ' Increment Month
    ' ---------------
    If CounterC=5 then
    If SetMonth=12 then
    SetMonth=1
    else
    SetMonth=SetMonth+1
    endif
    '
    Gosub FindDays
    If SetDay>CounterA then SetDay=CounterA
    endif
    If CounterC=6 then
    Gosub FindDays
    If SetDay=>CounterA then
    SetDay=1
    else
    SetDay=SetDay+1
    endif
    endif
    Pause ButtonRepeat
    TimeOut=0
    Goto SetupDisplayLoop
    endif
    '
    ' Set Button Pressed
    ' ------------------
    If SetButton=0 then
    CounterC=CounterC+1
    ' Increment Menu Item
    TimeOut=0
    If CounterC>6 then
    ' Save Data if all edit items exhaused
    LCDOut $FE,1,"Memorised"
    Attached Images Attached Images  

  3. #3
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Default Program continued...

    CounterA=SetHour
    If SetTime=1 then
    If CounterA>12 then CounterA=CounterA-12
    If CounterA=0 then CounterA=12
    endif
    Gosub ConvertBCD
    RTCHour=CounterB
    ' Save the Hours Value
    If SetTime=1 then
    RTCHour.6=1
    ' Save the 12 Hour Mode Flag
    If SetHour=>12 then RTCHour.5=1
    ' Save the 'PM' Flag
    endif
    '
    ' Save Minutes
    ' ------------
    CounterA=SetMin
    Gosub ConvertBCD
    RTCMin=CounterB
    '
    ' Save Seconds
    ' ------------
    CounterA=SetSec
    Gosub ConvertBCD
    RTCSec=CounterB
    '
    ' Save Year
    ' ---------
    CounterA=SetYear
    Gosub ConvertBCD
    RTCYear=CounterB
    '
    ' Save Month
    ' ----------
    CounterA=SetMonth
    Gosub ConvertBCD
    RTCMonth=CounterB
    '
    ' Save Day
    ' --------
    CounterA=SetDay
    Gosub ConvertBCD
    RTCDay=CounterB
    CounterA=SetYear+4
    CounterB=SetMonth
    If SetMonth<3 then
    CounterA=CounterA-1
    CounterB=CounterB+12
    endif
    CounterD=(SetDay+(153*CounterB-457)/5+365*CounterA+CounterA/4-CounterA/100+CounterA/400+2) MOD 7
    RTCWDay=CounterD+1
    '
    ' Do the Business
    ' ---------------

    I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl]
    Pause 1000
    Gosub SetButtonRelease
    Goto ReDisplay
    endif
    Gosub SetButtonRelease
    Goto SetupLoop ' Loop for Next Menu Item
    endif


    Pause 1 ' Kill 1mS
    TimeOut=TimeOut+1
    If TimeOut>20000 then goto ReDisplay

    End

  4. #4
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Arrow To sum it up..

    i did the same connections shown in the shematic , downloaded the same program (that is displayed here) inside PIC16F628A, gave 5VDc and checked the connections again. But i didn't see anything on LCD.......

    I even added a variable resistor (10 K) for the contrast of LCD and fixed the light in the middle position.

    SO now, you will keep on saying that i have to read datasheets??

    or you will try to help me in an effective way?

    i finished my MEMS laboratory and sent it to canado to be manifactured :-D

    Friday i will present it in front of jury and MONDAY..... i'll graduate :-) and since then, i'll pass a whooooooole month in the Carribean!

    But right now, since i am used to pressure of work, i'll continue and work on this real time clock. But not now.... during the last month i was sleeping only 4 hours daily and then, working 20 hours on this project non-stop , with just 30 minutes of break for each day.... imagine this situation!!?

    so i will just sleep......

    Please guys, take it into consideration and check that schematic and program... tomorrow i'll be well awake so i'll concentrate on your replies and try to accomplish what you told me to do..

    But please, please , please........ stop talking about datasheets...

    By the way:

    "The California Dept of Fish and Game is advising hikers, hunters and fishermen to take extra precautions and keep alert for bears while in the Yosemite and Mammoth areas.

    They advise people to wear noise-producing devices such as little bells on their clothing to alert but not startle the bear unexpectedly. They also advise carrying pepper spray in case of an encounter with a bear. It is also a good idea to watch for fresh signs of bear activity and know the difference between black bear and grizzly bear droppings. Black bear droppings are smaller and contain berries and possibly squirrel fur. Grizzly bear droppings have little bells in them and smell like pepper spray." :-)

  5. #5
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Eng4444,

    I wasn't trying to make you nervous by asking for drawings and code work. It just makes it easier to figure out what is going on. At first glance of the schematic I see the following:

    1) I think your LCD data lines are wrong. You should tie lines DB0 thru DB3 to ground then starting with DB4 tied to RA.0, DB5 to RA.1, DB.6 to RA.2 and DB7 to RA.3. The Read/Write pin on the LCD needs to go to ground. I tried to get the Datasheet (don't you just love it?) from Winstar but you have to signup with them to get these and I'm waiting to hear back from them so I can verify these connections when using a 4 bit bus. The couple of types of LCDs and VFDs I use start with DB4 when using 4 line bus connections.

    2) Pin 3 on the DS1307 needs to go either to a backup battery or tied to ground if you're not using the battery.

    3) You should change the pull up resistors on the SCL and SDA lines from 10K to 4.7K.

    4) I realize you had a hard time getting this drawn out but I don't see any capacitors. You need a .1uF on the power supply lines of EACH device as close to the device as possible. You should also have a .1uF and a 10uF on each side of the voltage regulator if that's how you are powering this project.

    You did mention that you have a potentiometer connected to the contrast pin of the LCD. I didn't see that on the drawing.

    Start with the above and try the program above. This may just take care of your problem. I have not sat down with the code. I trust that you have checked and rechecked that. Keep in mind that a single character wrong somewhere can keep it from working correctly. Someone recently had LCBOUT instead of LCDOUT. Big difference!

    Good luck!

    BobK
    Last edited by BobK; - 7th June 2006 at 19:56.

  6. #6
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Lightbulb LCD datasheet.

    Hello again :-)

    i just wanted to check befor sleeping if someone has answered. and Here i found yours BobK.

    thank you for the notes. I'll take them into consideration tomorrow.

    Here i attached the datasheet for you. So don't wait for winstar... sometimes they take lot of time.

    i hope i provided you with everything.

    By the way,

    the matter of variable resistor wasn't included because i just forgot to put it. But i assure you that i connected it in a good way and worked fine.

    So in case you wanna include or add something, i'll be thankful for the time you gave to me.

    Good night now... i'm soooooooooooooooooooo tired :-(
    Attached Images Attached Images  

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Better LCD Data sheet

    BobK,
    The "datasheet" Eng4444 posted was a bit sparse, but did reference the KS0066 or equivalant controler.

    Hope this helps, and it looks like you are correct about the data lines to the LCD, they should be D4-D7 (not D0-D3) in 4 bit mode.

    Steve B

  8. #8
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Thumbs up This looks sooooo familiar.

    There is project building. Planning and physically building a project. Writing the code and testing. When it does something unexpected (that would include not working). There is “troubleshooting”.

    Troubleshooting is an art. There are efficient ways and there are inefficient ways to accomplish the same end. The problem seems to be that some people just want the answer, not the procedure. They seem to think that someone can see their circuit, and mystically, clairvoyantly, pass their long-distant hand over the program or circuit and KNOW what their mistake is.

    Real problems arise when the person ASKING for HELP thinks the helper is just asking silly questions and asking them to do silly things. All that the person ASKING for help wants is an ANSWER. So they end up DEMANDING that the foolish, silly, questions STOP, and GIVE ME THE ANSWER that I need.

    So we are “stuck” with the “basic” truthful ANSWER , “I Don’t Know”.

    See also

    Quote Originally Posted by Eng4444 View Post
    i did the same connections shown in the shematic , downloaded the same program (that is displayed here) inside PIC16F628A, gave 5VDc and checked the connections again. But i didn't see anything on LCD.......
    ...SO now, you will keep on saying that i have to read datasheets??

    or you will try to help me in an effective way?

    Friday i will present it in front of jury and MONDAY..... i'll graduate :-) and since then, i'll pass a whooooooole month in the Carribean!

    ...so i will just sleep......

    Please guys, take it into consideration and check that schematic and program... tomorrow i'll be well awake so i'll concentrate on your replies and try to accomplish what you told me to do..

    But please, please , please........ stop talking about datasheets...
    -Adam- (this was mis-posted (by me) should have gone in answer to: http://www.picbasic.co.uk/forum/show...2&postcount=25
    Last edited by Pic_User; - 20th October 2008 at 16:09.
    Ohm it's not just a good idea... it's the LAW !

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 12:13
  2. Real Time Clock
    By in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd June 2012, 04:52
  3. real time clock - PCF8583
    By maria in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th April 2010, 15:41
  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 : 1

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