Continue to Site

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.

  • 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.

Need help with LCD 16x2 hitachi HD44780 and 16f84a

Status
Not open for further replies.

evilsent

New Member
Hi every one! this is my first post here..:)
Im trying to send from the pic a line text " hello" to the LCD. My first try was successfull with PIC SIMULATOR IDE. I programmed the code and used the LCD simulator..and it showed: "Hello". Today I programmed the code using Micro code studio plus and Pic basic pro.

This is an extract from Micro code studio Help about LCDOUT

PICBasic asumes the LCD is connected to specific pins unless told otherwise. It assumes the LCD will be used with a 4-bit bus with data lines DB4 - DB7 connected to PICmicro PORTA.0 - PORTA.3, Register Select to PORTA.4 and Enable to PORTB.3. It is also preset to initialize the LCD to a 2 line display.

so i´ve used this diagram with the exeption that i connected ra4 directly to RS pin in LCD, and i´ve connected to MCLR with Vdd with a 10k resistor, the capacitor for contrast in the LCD is a 10k one, the vss pin in the micro is connected directly to ground and vdd pin directly to +5v:

**broken link removed**

this is my code:

pause 1000
loop:
High PORTB.2 ' turn on a Led
pause 500
LCDOUT $FE, 1, "Hello"
low PORTB.2 ' turn off the led
pause 500
goto loop
end

i didn´t use DEFINE coz according to the LCDOUT statement i´ve showed to you, from Microcode studio help. The diagram and the code are just what i need. Just for the record: i´ve read all the info in the internet about interfacing pics and LCD

The LCD isn´t showing anything. But the led is actually working.

Can anybody help me???
 
Last edited:
evilsent said:
so i´ve used this diagram with the exeption that i connected ra4 directly to RS pin in LCD, and i´ve connected to MCLR with Vdd with a 10k resistor, the capacitor for contrast in the LCD is a 10k one, the vss pin in the micro is connected directly to ground and vdd pin directly to +5v:

Have you included the resistor from RA4 to Vdd? This is needed as RA4 is an open collector output and can therefore only pull the output low.

Mike.
 
No i haven´t included the resistor, is it mandatory in order to make things right??? and if it´s so..it´s a 4700 = 4.7k resistor??. I´m gonna try with this resistor. Thanks 4 the advice. Is anything else wrong with my project???

Thanks 4 the help Mike.
 
Yes, you need the resistor. 4700Ω =4.7kΩ but anything around that value will work (2k to 20k).

Mike.
 
Hi,
please try this:

' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1,"Hello"
end


LCD Connection
Pin1=Vss: connect to ground
Pin2=Vdd: connect to Vcc=5V
Pin3=Vo: connect to middle pin of the POT(20K) to control brightness
Pin4=RS(register select): connect to micro pins that specify in the software(RB1)
Pin5=RW(Read/Write): connect to ground because we want to only write
Pin6=E(Enable): connect to micro pin that specify in the software(RB0)
Pin7 to 10: No connection
Pin 11 to 14: connect to RB4 to RB7
Pin15: connect to Vcc with a resistor(100 or 200 ohm resistor is good)
Pin16: connect to ground.
pin 16 and pin 16 are for backlights

the other two pins of pot should connect to VCC and ground and you should connect the MCLR with a 4.7K or 10K resistor to the VCC.
 
Last edited:
Thank you guys for helping me...i´ll try your suggestions when i get home...and i´ll let you know what happened.

greetings
 
william, you said that the schematic that i used, uses the lower 4 bits of porta.

What does it mean?? i Thought that when you set:
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0

it means that you wanna use DB0-DB3 as data bus. Or it really means the pins at the port specified. PORTA.0, PORTA.1.......,PORTA.3 in the PIC?????

Because now i followed the schematic im my breadboard and nothing happened..well the led works fine....and the LCD at least turns on all lines showing almost transparents squares.
Is because of the code????

And if its my code..can anyone show me a code for this schematic that actually works?

Thank you all!
 
Last edited:
It should work as it is.

Here is the example code from **broken link removed**

Code:
' PicBasic program to demonstrate operation of an LCD in 4-bit mode
'
' LCD should be connected as follows:
'       LCD     PIC
'       DB4     PortA.0
'       DB5     PortA.1
'       DB6     PortA.2
'       DB7     PortA.3
'       RS      PortA.4 (add 4.7K pullup resistor to 5 volts)
'       E       PortB.3
'       RW      Ground
'       Vdd     5 volts
'       Vss     Ground
'       Vo      20K potentiometer (or ground)
'       DB0-3   No connect

        Pause 500       ' Wait for LCD to startup

loop:   Lcdout $fe, 1   ' Clear LCD screen
        Lcdout "Hello"  ' Display Hello
        Pause 500       ' Wait .5 second

        Lcdout $fe, 1   ' Clear LCD screen
        Lcdout "World"
        Pause 500       ' Wait .5 second

        Goto loop       ' Do it forever

As you can see the only thing that could be wrong is the omission of the pullup on RA4. If it doesn't work then check your wiring.

Mike.
 
im sure that the wiring between lcd and the pic is correct, im sure my code is correct as the one mike posted. The thing is that when the pic start to work..the lcd show me the 2 lines with all the pixels "on" in all of the 16 positions. What i did next was to disconect the wires from LCD...except the ground, +5v, and contrast. And the LCd just show one line with all the pixel "on"
. IS it normal??? or my LCD is damaged??

I dont know what else to try.... :(

edit: i tried the code above and nothing the same thing happened :'(
 
Last edited:
It looks like your LCD is OK. The reason you only see 1 line with only power connected and 2 lines with the pic connected is that the pic is initializing the LCD to be a 2 line unit. Can you adjust the contrast from all black through to all light?

Mike.
 
IT WORKS!!!!!!!! the reason that it wasn working was coz the 10k POT was defective..i tried to adjust the contrast and nothing happened...i change te pot and everything goes fine!!!!!!!!!

Thank you people for all the help u gave me!!!

Thanks mike! thanks william at the blue room and to amindzo
 
Hi every body,
the lcd connection that pommie siad is a default one(that don't need any define in software) and if you want to connect lcd to PORTB or PORC and so, on you should define the lcd parameters as i said befor.
it is better to make a 100 or 150 ms delay to make the lcd ready befor you want to write on lcd.
 
Last edited:
rshafi68 said:
can i groung the vss pin3 ,then what will be the result of lcd brightness?

It's very unlikely to work - although a very few LCD modules are usable like that - but the vast majority require a preset to adjust the contrast.

If it's set too low you get absolutely nothing, and if it's set too high you get solid black squares.

It's actually a useful way of checking if things are working - if the LCD isn't being initialised correctly, turning the contrast up will produce a single row of black squares, this happens as well (obviously) with the LCD not connected, except for power and contrast control (because it's not getting initialised).
 
I think it depends on the LCD, in my case when i set to ground pin 3 ( contrast adjustment ) of the LCD...it just showed all pixels "on" , contrast set to high in that case. It was necesary to use a 10k POT to adjust the contrast in order to see the text i programmed instead of black squares in the 2 lines of LCD.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top