hhhsssmmm
Member level 1
Hello
Im using a PIC18F4220 @ 20Mhz ceramic with C18 compiler.
Im trying to do a simple test program where the PIC sends out the letter 'a' to an LCD connected to PORTD (8bit mode).....no nibbling!
However I can not get a consistent result each time the PIC is powered up. The behaviour is that sometimes the letter 'a' is displayed perfectly and sometimes it is not displayed at all. Sometimes the cursor simply blinks or sometimes the display remains completely blank.
Im using the following LCD module from Palm Technology Co., LTD
Display: LCD 20x2
Model: PMC2002D9-SBLW-1
Below is my test program. Please can some one help me to get the stable letter 'a' result each time the PIC is powered up.
Thank you
Haseeb
Im using a PIC18F4220 @ 20Mhz ceramic with C18 compiler.
Im trying to do a simple test program where the PIC sends out the letter 'a' to an LCD connected to PORTD (8bit mode).....no nibbling!
However I can not get a consistent result each time the PIC is powered up. The behaviour is that sometimes the letter 'a' is displayed perfectly and sometimes it is not displayed at all. Sometimes the cursor simply blinks or sometimes the display remains completely blank.
Im using the following LCD module from Palm Technology Co., LTD
Display: LCD 20x2
Model: PMC2002D9-SBLW-1
Below is my test program. Please can some one help me to get the stable letter 'a' result each time the PIC is powered up.
Thank you
Haseeb
Code:
#include <p18f4220.h>
#include <delays.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
void SendLCD(unsigned char Byte, unsigned char type);
#define LCD LATD //LCD Latch PORT
#define LCD_RS LATEbits.LATE0 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATEbits.LATE2 //Enable (Starts data read/write)
void main (void)
{
ADCON1 = 0x0F; //SET ALL PORTS as DIGITAL I/O
PORTD = 0; //initiallize PORTD
TRISD = 0x00; //LCD output
PORTE = 0; //initiallize PORTE
TRISEbits.TRISE0 = 0; //LCD Register Select (to LCD Pin 4)
TRISEbits.TRISE2 = 0; //LCD Enable (to LCD Pin 6)
//Initialize the LCD
LCD = 0x00; //clear LCD PORTD pins
Delay1KTCYx(100); //delay 20mS
SendLCD(0x03,0); //Initialization command
Delay1KTCYx(25); //delay 5mS
SendLCD(0x03,0); //Initialization command
Delay10TCYx(75); //delay 150uS
SendLCD(0x03,0); //Initialization command
Delay10TCYx(75); //delay 150uS
SendLCD(0x3C,0); //Interface lenght is 8 bits long, 2-lines, 5x10 dots
Delay10TCYx(25); //delay 50uS
SendLCD(0x10,0); //Turn off LCD
Delay10TCYx(25); //delay 50uS
SendLCD(0x01,0); //Clear LCD
Delay10TCYx(25); //delay 50uS
SendLCD(0x06,0); //Increment the cursor after each byte written
Delay10TCYx(25); //delay 50uS
SendLCD(0x0F,0); //Turn on LCD, cursor on, cursor blinking on
Delay10TCYx(25); //delay 50uS
SendLCD(0x80,0); //Send 0x80 to set line to 1
Delay10TCYx(25); //delay 50uS
SendLCD('a',1); //print letter 'a' on LCD
while(1); //loop forever
} //end of main()
void SendLCD(unsigned char Byte, unsigned char type)
{
LCD_RS = type; //Set whether it is a Command (0) or Data/Char (1)
LCD = 0x00; //Clear the LCD PORTD
LCD = Byte; //assign the new data to the LCD PORTD
//Toggle the E(enable)
LCD_E = 1; //Set Enable High
//Delay 5uS
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
LCD_E = 0; //Set Enable Low
}