pic16F84A interface

rareven

New member
i have a cfah2002a-ymc-jp display that i would like to controll using a PIC16F84A micro controller, prefer to use 4 bit interface

i need help with knowing when to toggle the different pins to send commands to the LCD...

example code in HITECH-C or Assembly would be very much appreciated... if you would like to see the code that i have so far that does not work at all plz email me at henry_stikeleathe@eku.edu
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Since I hate the PIC instruction set, I won't attempt to use assembly language. And since this involves writing to individual port bits, standard C would need some functions written, which I'm too lazy to do.

So here is a sample in pseudo-code (to keep things simple I will use a delay, instead of testing the busy flag, and the port pin controlling R/W is assumed always low):

Code:
LCD_Write (byte type,  byte data)
{
     if (type == command) set RS pin low    /* if display command */
     else set RS pin high     /* if display data */

     shift data byte right 4 bits and put upper nibble to data port

     set E pin high
     set E pin low

     put lower nibble of data byte to data port

     set E pin high
     set E pin low

     wait 2 milliseconds
}
If you need more info, or help with the initialization procedure, say so.
 

rareven

New member
i tried the same thing in assembly

i set all pins 0
i set rs or rw to what they need to be respectivly

then i turn on the pins connected to the LCD 1 at a time using
BSF portb, (pinnumber) (4,5,6,7)

i dont change them all at the same time, one after the other ??
wonder if thats my problem ill try it after sending this

and then i toggle E high and then back to low
 
There is a lot of missing info, such as:

Is the display being initialized successfully?

Have you ever successfully written any characters?

I will guess "none of the above". BTW, you can't use the example code to do the initialization in 4 bit mode, because that requires single nibble writes with delays. Also, you need to be sure not to exceed the timing limits in the data sheet; like the 500nS cycle time for E, and minimum 230 nS high. This will be dependant on your clock frequency unless you insert delays or NOPs.

It doesn't matter when the data pins change, or RS, or R/W. It only matters what state they are in when E toggles H>L.
 

rareven

New member
no succesful anything, and i am creating the E signal with the 16f84, at 4 Mhz so each istruction takes 1 uS to complete, and the example C code doesnt work....
 

rareven

New member
and im using a 20 mhz scope and i cant even see the rise or fall from high to low.. so i really dont think thats the cause when it falls or rises it falls and rises VERY fast.... E is toggling

how should one initialize the LCD, like crystal fontz says in data sheet or what???
 
I think rise and fall time are not at issue here, rather the time at 1 or 0 state. But if your instruction execution time is 1 uS, then I think the minimum time requirement is met.

I'll spell out the init sequence, just like it shows in the data sheet (almost).

E, RS, R/W all start out low, D0-D3 of the LCD are wired low.

Do delay of 15 mS after power is applied

Put 0011 (0x3) on data port (d7=0, d6=0, d5=1, d4=1)

Toggle E: L>H>L

Do a delay of 5 mS

Toggle E: L>H>L

Do a delay of 100 uS

Toggle E: L>H>L

Put 0010 (0x2) on data port

Toggle E: L>H>L

(Starting here you may use the two nibble write routine that I posted earlier)

Send command 0x28 (the upper nibble 0x2 is already on the data port)
Toggle E: L>H>L (upper nibble of 0x28)
Put 1000 (0x8) on data port
Toggle E: L>H>L (lower nibble of 0x28)

Do a delay of 2 mS (unless you use the 2 nibble write routine, which has the delay included).

Send command 0x01
Put 0000 on data port
Toggle E: L>H>L
Put 0001 on data port
Toggle E: L>H>L

Do a delay of 2 mS (unless you use the 2 nibble write routine, which has the delay included).

Send command 0x06
Put 0000 on data port
Toggle E: L>H>L
Put 0110 on data port
Toggle E: L>H>L

Do a delay of 2 mS (unless you use the 2 nibble write routine, which has the delay included).

Send command 0x0C
Put 0000 on data port
Toggle E: L>H>L
Put 1100 on data port
Toggle E: L>H>L

The display should now be initialized with the cursor at home (cursor is not turned on, so you wont see it). If you want the cursor on, use 0x0E instead of 0x0C in the last command. You can now write characters (with RS pin high), in the same fashion, or use the function I posted.
 
Last edited:

rareven

New member
i think i know what im doing wrong now :)

d0-d3 on my setup are FLOATING................
i read that when in 4 bit mode they were dont care bits...
could that be the reason i wonder.......
 

rareven

New member
again Thanks for all your help, maybe i can get this thing to work, im in an independent study here at Eastern Kentucky University, were trying to create an intrepreter board for the RCX lego robots so we can talk to them with PIC microchips and the like. Later out intention is visual recongnition..
 
Well, let us know if all that works. You see, I've never used 4 bit mode myself, so this stuff I posted is what I would use if I did, so I cannot say for absolute certain that its right.

Technically, having D0-D3 floating shouldn't matter, but I seem to recall someone else solving a problem by tying them low. I cringe at leaving cmos inputs floating unless the data says there is an internal pull-up/down (which isn't told in this data sheet).
 

rareven

New member
yah if this all works when i get around to trying it this would be one thread to put somewhere like in a FAQ or something.

(have lots of other very important homework to deal with first)
 

rareven

New member
ITS WORKING!!

Guess what, when i tied all the extra data pins to ground it works, like a charm

thanks guys
remember to tell others of the discovery :)
 
Top