LCD programming with PIC

Discussion in 'Embedded Systems and Microcontrollers' started by Zeta7, Mar 12, 2011.

  1. Zeta7

    Thread Starter New Member

    Mar 9, 2011
    1
    0
    Greetings,

    I am new to the PIC Micro world although I have experience in the 80C51 world. I have copied the code that MMcLaren has posted here and have connected the PIC 16F690 as shown in his diagram as well. However, I get absolutly nothing displayed on the LCD. Is there someone out there that can help me get a single character displayed on this 44780 LCD panel (It is 20x4)?

    BTW, I am using te low pin count demo board that came with the Pickit2 and had realized that RC7 was not connected to the demoboard's headder so I changed the code to use RC5 instead. Still no display.
     
  2. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Hi Zeta7,

    With the LCD 'E' pin connected to RC5, the PutNyb code should look like this;

    Code ( (Unknown Language)):
    1. PutNyb
    2.         andlw   0x0F            ; mask off left nybble            |B0
    3.         iorlw   b'00010000'     ; set lcd RS bit (RC4)            |B0
    4.         skpc                    ; C=1 (RS=1)? yes, skip, else     |B0
    5.         xorlw   b'00010000'     ; clr lcd RS bit (RC4)            |B0
    6.         movwf   PORTC           ; assert D7..D4 & RS pins         |B0
    7.         iorlw   b'[COLOR=Blue]00100000[/COLOR]'     ; set lcd E bit ([COLOR=Blue]RC5[/COLOR])             |B0
    8.         movwf   PORTC           ; E = 1 (strobe)                  |B0
    9.         xorlw   b'[COLOR=Blue]00100000[/COLOR]'     ; clr lcd E bit ([COLOR=Blue]RC5[/COLOR])             |B0
    10.         movwf   PORTC           ; E = 0                           |B0
    11.         return                  ;                                 |B0
    12.  
    You might also add a clrc instruction in front of the first DelayCy(30*msecs) instruction in the LCD initialization code. It shouldn't be necessary because of the clrf STATUS instruction at the reset vector but if you've added any code to the program you may have accidentally upset the Carry status flag before we get to the LCD initialization code.

    Cheerful regards, Mike

    Code ( (Unknown Language)):
    1. ;
    2. ;  initialize LCD in 4-bit interface mode
    3. ;
    4.         [COLOR=Blue]clrc[/COLOR]                    ;                                 |B0
    5.         DelayCy(30*msecs)       ; delay 30-msecs after power up   |B0
    6.  
     
    Last edited: Mar 13, 2011
  3. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,017
    What language and what compiler?
     
  5. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    It was assembly language using MPASM. Here's the code from the original thread.

    Cheerful regards, Mike, K8LH

    [​IMG]
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,017
    Why do you want to punish yourself with assembler too? Using C would be a log easier and there are already tested functions out there.

    Assuming you have debugged you code, and all the pins on the LCD toggle like they are supposed too, the next most likely cause is timing. Delays between commands and characters. Search on this forum. I believe it was ThatOneGuy that posted recommendations on timing.

    This all assumes your code is working properly in the first place and it is initializing the LCD correctly.
     
  7. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Hi Spinnaker,

    I'm not sure if you're addressing Zeta7 or me? I'll just mention that I do program in C as well as assembler but the original poster on the original thread was using assembler. Anyway, the example code works fine and the timing is right out of the HD44780 Datasheet and is derived from a cycle accurate general purpose delay subsystem that supports almost any clock (4, 8, 12, 16, 20-MHz, etc).

    I'm sure that if you were to suggest looking at C as an alternative to assembler that it would seem much less abrasive than your criticism about using assembler.

    Cheerful regards, Mike

    [​IMG]
     
    Last edited: Mar 15, 2011
Loading...