View previous topic :: View next topic |
Author |
Message |
carol1988
Joined: 23 May 2018 Posts: 2
|
Help with 16x2 LCD |
Posted: Tue May 29, 2018 1:00 am |
|
|
Hi,
For quite a long time now I've just been coding and simulating with proteus and every of my designs all works fine on simulation. But i tried building a physical device and decided to test out a 16x2 LCD with PIC16f877a microcontroller first but its not displaying anything even after working fine on proteus.
Here is the code and i can't really tell what I'm not doing right as it worked fine on simulation.
Code: | #include <16f877a.h>
#device adc=10 // Set ADC resolution to 10Bit
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include "flex_lcd.c"
void main()
{
// ADC module is slow, needs some time to adjust.
/* Peripherals Configurations */
lcd_init(); // Turn LCD ON, along with other initialization commands
while(1) // infinite loop
{
lcd_gotoxy(1,1); // point LCD cursor to col1 row1
lcd_putc(" ASK UCHE SOME"); // print on LCD
lcd_gotoxy(1,2); // point LCD cursor to col1 row2
lcd_putc(" QUESTIONS "); // print on LCD
}
}
|
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue May 29, 2018 3:21 am |
|
|
Read the sticky at the head of these posts.
Mike
PS First thing, LCDs need time to settle down.
I.e. you need a delay before initialising the LCD! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue May 29, 2018 3:32 am |
|
|
Also just do something much more basic. Single LED (with a suitable current limiting resistor on the pin feeding it), and code like:
Code: |
#include <16f877a.h>
#device adc=10 // Set ADC resolution to 10Bit
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include "flex_lcd.c"
void main(void)
{
while(TRUE)
{
output_toggle({PIN_xx); //where 'xx' is the pin you have the LED on
delay_ms(1000);
}
}
|
And check the LED does flash 1 second on, one second off.
Proteus will 'believe you' if you say you have a 4Mhz clock. The real chip requires a suitable crystal, correctly wired, and the right power connections, MCLR etc., before it'll start. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue May 29, 2018 4:47 am |
|
|
I agree with Mike and Mr. T ! Run Mr; T's program and confirm the LED flashes at the correct speed. This will confirm you've got most of the hardware properly wired. Be sure to add the 22pfd caps at the xtal pins ! Proteus is STUPID and will have the PIC 'run' without them !!! It SHOULD however report a FATAL ERROR message.
What Mike's says...
//
delay_ms(500); // delay to allow LCD harware to 'boot'
lcd_init(); //CCS function to change LCD to 4 bit mode
//rest of code
This will add the required delay to allow the LCD module to 'startup' and configure to it's factory defaults(it's a spec in the LCD module datasheet 'somewhere'). Each LCD module series requires different delays and while 500ms may seem like a lot, I've never had one not startup and work properly using that time value in almost 3 decades of using PICs and LCDs. You can always change to a smaller value, say 400,300,200. Just be sure to properly test several times(all 'cold boots' ) before convincing yourself it works fine.
Jay
edited cause I put the cart before the horse...oopsy
man I can stare at the glaring mistake and NOT see it, turned 65 last Saturday so can I use that as an excuse ??
Last edited by temtronic on Tue May 29, 2018 10:58 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue May 29, 2018 7:40 am |
|
|
On the boot delay, there are several parts 'to' this:
The original specified 'ready to go' time for the Hitachi LCD controller after power was applied was 90mSec. However big caveat, the controller does not actually start to boot till it's supply is over 4.2v. Most PIC's start well below this. So more time is needed. Depends on how fast the supply actually rises but can be anything from just a couple of mSec to several tens of mSec.
Then 'clone' chips are often significantly slower to boot than the original controller. I've seen several that can take 250mSec+.
Combine these, and you can see how a time like 500mSec becomes worth using for safety..... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 29, 2018 8:15 am |
|
|
temtronic's post shows the delay in the wrong place. He needs to edit
his post and put the 500 ms delay before the call to lcd_init(). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue May 29, 2018 10:21 am |
|
|
Official whoops.
I didn't spot that.... |
|
|
|