Date and Time Display using LCD and RTC

Discussion in 'Embedded Systems and Microcontrollers' started by innovationlabs, Oct 29, 2010.

  1. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    Hi,

    I have designed a small circuit using a P89V51RD2-BN controller and an RTC, DS12887 along with a 16x2 LCD display. The crystal used has a frequency of 22.118MHz.

    The First Line of the LCD is supposed to display time as follows:
    15:27:36
    Second Line:
    FRI 29 OCT 2010

    I first programmed and started the RTC using the code given in "RTC starter.txt" to initialize the RTC with time and date, and start the oscillator, as I didn't want to use a keypad.

    Next I burned the final code, given in "digital_clock.txt" into the controller, but the LCD shows nothing at all, except for the black rectangles on the first line.
    The circuit and the codes are attached below.

    Any help please?
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,017

    First start simple. Instead of worrying about the RTC just print something to the display. See if that works.

    Next verify all of your wiring. Can you put you MCU into debug mode? If so write some code to toggle each pin on your LCD. Verify that each bit is changing as it should.


    Also check the delay before the LCD is initialized after power up. I had one that did not need a delay but when I swapped it out with a second LCD, it did not work. I put a 100ms delay in before the init code and it worked fine.
     
    Last edited: Oct 30, 2010
  3. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    Sounds like your probably sending data to the LCD before the LCD has had time to boot. Try to add in a delay to give the LCD time to boot.
     
  4. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    I have already placed a 200ms delay at the start of the code as the RTC requires about 200ms after which it becomes accessible. Also before any command or data is sent to the LCD, the LCD's busy flag is checked.

    I will try individual bits of code to check each changing bit.

    Are the code and circuit fine or do they need changes? I read in a few sites that the contrast pin of the LCD can be grounded for maximum contrast, while other sites say that maximum contrast will make each character appear as a black block! Which one is it? I do not want to use a pot in the final working.
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You need a pot for contrast, the display will vary with temperature. You might find a value that works well enough and can use a pair of fixed resistors.
     
  6. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    It depends on the LCD. I can ground mine and you can still read it fine. Put a pot on it and I can adjust it the way I want it. Different LCD's are different though so yours may need that contrast pot to work. I don't think so because having all black bars at the top and nothing on the lower bar makes me thing your failing in your initialization or missing your timing some how. I beleive when your LCD fully inits it will show all black bars for a second then show your text.
     
  7. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    I guess I'll have to do just that: add a pot..
    @maxpower097, I had the same doubt about the black bars being on only the first line. I'm pretty sure the LCD commands are correct. I'll try it as soon as I can.
    Thank you all!
    Any more suggestions in the meanwhile are welcome!
     
  8. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Character mode LCD displays must be initialised before they will display any data. An initialised display will generally just show a line of black blocks.

    Get the data sheet for your display controller (eg HD44780, KS0070, KS0066U or whatever controller you display uses) and follow the initialisation sequence in the data sheet to the letter being sure to include all the recommended delays between various instructions.
     
  9. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    I've partially solved the problem!
    I'm using Proteus to simulate the circuit. The problem was where I had used the flag register of the LCD to check if it was busy, and send a command when it was free. Seems it kept going on in an infinite loop waiting for the flag register to change. When I replaced the subroutine by a simple delay, it began working fine! One problem down, one to go..
    The issue remaining is that the data being displayed on the LCD starts shifting, i.e. it's supposed to display date and time like this:
    12:22:37
    SUN 31 OCT 2010

    it displays this for the first time correctly, then it begins shifting, like:
    38:39:40
    NTU 43 NFE 2047
    , something like that.
    Actuallu the controller is supposed to retrieve the time and date fields from the RTC, decode it and display the values respectively, but I noticed it uses the seconds value many a times in between for other values like date, month year, etc.

    I have checked the code and the register addresses used to access the RTC are correct, no problem there.

    Proteus seems to show logic contentions on the port lines connecting the controller and the RTC whenever data is READ FROM the RTC, and not WRITTEN TO the RTC... And I don't know how to fix that... :confused::confused:
     
  10. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    I've checked almost every step using Proteus..
    I changed the code so all the fields of the RTC are copied to RAM locations of the controller. It seems the controller just does not or cannot copy all the data values from the RTC!

    I'm uploading the Proteus file and the code..
    Help please!
     
  11. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    Makes since if you think about it. How can the LCD flag be busy if its not initialized. After its initialized you should be able to use the LCD busy bit.
     
  12. innovationlabs

    Thread Starter New Member

    Jul 12, 2009
    7
    0
    Please read my code. I have initialized the LCD properly. The problem I am facing is that the controller is not reading the proper values from the RTC.
    A few articles as well as the datasheet of DS12887 states that sometimes if you try to access the RTC when it is updating causes issues in reading the registers. Even though I put a provision in the code I just tried, the simulation still does not work. Maybe I'll have to burn it now and check.
     
  13. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    Unfortunately I'm not familiar with these chips. I'm sure someone else is so just give it a day and I'm sure someone will check it out. If your gettting data to the LCD, but its just garbled, it could be a baud rate issue, or it could be a conversion issue where you need to take the reading from the RTC and convert it from binary to decimal or something. I'm just guessing.
     
  14. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    You don't say which controller your LCD display uses but assuming its the HD44780 (the most common controller in use) then the initialisation in your code does not come anywhere near the correct initialisation sequence.

    Get the Hitachi HD44780 data sheet and take a look at recommended the 8 bit initialisation sequence on page 45 of the PDF file, follow the sequence to the letter and your LDC will work.
     
Loading...