#pragma config FOSC = HS // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include<xc.h>
#include"lcd.h"
#define _XTAL_FREQ 20000000
int main()
{
TRISB = 0X00; // Configure all the LCD pins as output
PORTB = 0X00;
char i,a[]={"Good morning!"};
lcd_init();
lcd_write('H');
lcd_write('e');
lcd_write('l');
lcd_write('l');
lcd_write('o');
lcd_write(' ');
lcd_write('w');
lcd_write('o');
lcd_write('r');
lcd_write('l');
lcd_write('d');
lcd_goto(0xc0); //Go to Next line and display Good Morning
lcd_data(a);
while(1);
}
#include<xc.h>
#include"lcd.h"
#define _XTAL_FREQ 20000000
//*********************************************************//
#define LCD_RS PORTBbits.RB5 // Register select
#define LCD_EN PORTBbits.RB4 // Enable
//*********************************************************//
// write a byte to the LCD in 4 bit mode
//*********************************************************//
void lcd_write(unsigned char c)
{
PORTB = (PORTB & 0xF0) | (c >> 4); // Send higher nibble
LCD_EN = 1;
LCD_EN = 0;
PORTB = (PORTB & 0xF0) | (c & 0x0F); // Send lower nibble
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(40);
}
//*********************************************************//
// Clear and home the LCD
//*********************************************************//
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}
//*********************************************************//
// write a string of chars to the LCD
//*********************************************************//
void lcd_data(const char *s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
//*********************************************************//
// Go to the specified position
//*********************************************************//
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}
//*********************************************************//
// initialise the LCD - Put into 4 bit mode
//*********************************************************//
void lcd_init(void)
{
LCD_RS = 0; // write control bytes
__delay_ms(15); // power on delay
PORTB = 0x3; // attention!
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(5);
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(100);
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(5);
PORTB = 0x2; // to set 4 bit mode
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x08); // display off
// lcd_write(0x0F); // display on, blink curson on
lcd_write(0x0C); // display on, cursor off, blink off
lcd_write(0x06); // entry mode
// lcd_write(0x80); // Move the cursor to beginning of first line
}
/* write a byte to the LCD in 4 bit mode */
extern void lcd_write(unsigned char);
/* Clear and home the LCD */
extern void lcd_clear(void);
/* write a string of characters to the LCD */
extern void lcd_data(const char *s);
/* Go to the specified position */
extern void lcd_goto(unsigned char pos);
/* intialize the LCD - call before anything else */
extern void lcd_init(void);
extern void lcd_putch(char);
/* Set the cursor position */
#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
LCD_EN = 1;
LCD_EN = 0;
Are you sure the timing of the I/Os is correctly sized? According to the snippet below taken from your code, and based on the crystal frequency, pin E is kept in high level by only 200 ns:
Code:LCD_EN = 1; LCD_EN = 0;
Check the LCD controller datasheet about timming specifications.
my contrast pin is connected to potentio meter, i set it to max levelBe careful how you write to the PORT on these chips that do NOT have LAT registers - looking at some of the sequences you have, you are opening yourself up to the RMW problem. IF that is the case then the LCD controller will not be getting the signals that you think it is.
For example, you load the bottom nibble of PORTB and toggle RB4 in consecutive instructions - if there is any loading on on any of the pins then the RMW operation on the port can change the bit values.
You are better off to create a shadow register that you update and then write that to PORTB as a whole value.
A quick look on the Internet shows that the LCD controller is supposed to be a 'standard' Hitachi (I'm guessing HD44780 but only in 4-bit more). If that is the case then the timing of the initialisaiton sequence is critical. However looking at your code, you would seem to be OK (except for an excessively long delay in 'lcd_write()').
can you explain it little more
If the device has a 'contrast' pin, then turn up the voltage on that until you get all of the character locations showing as faint blocks of dots and then back it off a little. If the contract is down too low then it is possible the characters are there but just not showing - setting the contract level as I've mentioned should make then visible.
Susan
i read some where that the delay should be in 'us', i tried with delay in 'us' , please tell me how can you say that delay in ns based on crystal frequency
Hi,
I assume there is a timing problem..
--> I see no other chance than to take the datasheet and compare each specification item by itmem with your application.
(Code, scope pictures).
Klaus
can you explain it more;It begins with applying voltage --> check when the supply voltage is valid --> check time until you send the first instruction.
(Maybe there is a RESET signal involved.)
Then check if the first byte really has the value that you expect...
Klaus
I can´t anwer this. I don´t have a PC066GL in my hands.i don't have PC066PGL datasheet, but i do have HD44780, will it useful for that
The given recommendation makes sense only with the specification of the datasheet.can you explain it more
What do you mean by that? Show us a picture of the display and tell us what you think it should be showing.actually whatever the lcd display i have is 90's display,
Where can we find "what you expected to be printed on the LCD"?and what you expected it to show.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?