View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 23 Jun 2012 Posts: 22
|
16F877A LCD 4-bit MODE |
Posted: Tue Sep 25, 2012 10:20 am |
|
|
I tried out the following code in my development board. The compiler shows no error but I am not getting the output in LCD. Pls...anyone check this with your device and help me solve the error....pls...I am beginner.
Thanks in advance
Code: | #include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#define LCD_ENABLE PIN_D2
#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_DATA_PORT 08h
void lcd_init();
void lcd_cmd(char c);
void lcd_data(char d);
void lcd_init()
{
lcd_cmd(0x28);
delay_ms(200);
lcd_cmd(0x0c);
delay_us(10);
lcd_cmd(0x06);
delay_us(10);
lcd_cmd(0x01);
delay_us(10);
}
void lcd_cmd(char c)
{
output_d(c);
output_low(LCD_RS);
output_low(LCD_RW);
delay_ms(1);
output_high(LCD_ENABLE);
delay_ms(1);
output_low(LCD_ENABLE);
}
void lcd_data(char d)
{
output_d(d);
output_high(LCD_RS);
output_low(LCD_RW);
delay_ms(1);
output_high(LCD_ENABLE);
delay_ms(1);
output_low(LCD_ENABLE);
}
void main()
{
while(1)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_data('E');
lcd_data('L');
lcd_data('I');
lcd_data('T');
lcd_data('E');
lcd_cmd(0xC0);
lcd_data('w');
lcd_data('e');
lcd_data('l');
lcd_data('c');
lcd_data('o');
lcd_data('m');
lcd_data('e');
//TODO: User Code
}
} |
_________________ -humble request from a beginner |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Sep 25, 2012 11:10 am |
|
|
You're not the first to have LCD problems.
I'm assuming that you have proven that the board is working by flashing an LED.
Do a search on this forum for LCD problems. You'll get loads of suggestions.
Also try the LCD_flex driver, rather than writing your own.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Sep 25, 2012 2:42 pm |
|
|
The most obvious missing thing is the delay at the start. Most LCD's need significant time after power is applied before they can be initialised. You are calling your lcd_init, only a few uSec after the chip powers up. Add something like a 1/4 second delay before this.
Best Wishes |
|
|
[email protected]
Joined: 23 Jun 2012 Posts: 22
|
|
Posted: Fri Dec 21, 2012 6:08 am |
|
|
Flex_LCD Driver also does not work for me!
But I was able to display in LCD using AT-168 controller with the same hardware. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Dec 21, 2012 6:26 am |
|
|
Quick comments...
1) Title says 4 bit mode, but code is 8 bit mode.
2) As mr. t. pointed out, different LCD modules require different setup times. I typically powerup, wait 1 second, do LCD_init, wait another second and have NEVER had ANY module not run right.
3) I have used the 16F877/flex_LCD driver for years, so I know they will work together.
4) Then there's the non standard use of portD for both LCD control lines AND data. Pretty sure that will not work.
5) You should add comments to most lines of code so that a day, week, month form now, you'll know what you did and why. lcd_cmd(0x0c) means ??? as an example. It also helps others to figure out your code.
hth
jay |
|
|
|