I'm having problems getting my LCD screen to initialize properly I was wondering if anybody could tell me what I'm doing wrong.
I'm using a PIC18F2520
here is the datasheet for the LCD I'm using
http://www.sparkfun.com/datasheets/LCD/st7066.pdf
I'm trying to use 4 bit mode my pin setup is
Enable RB6
R/W RB5
RS RB4
Data7-4 RB3-0
This is my first time ever using a pic and I'm not that familiar with embedded systems in general. I have used this website as my reference for how to initalize the lcd screen http://joshuagalloway.com/lcd.html.
I'm using a PIC18F2520
here is the datasheet for the LCD I'm using
http://www.sparkfun.com/datasheets/LCD/st7066.pdf
I'm trying to use 4 bit mode my pin setup is
Enable RB6
R/W RB5
RS RB4
Data7-4 RB3-0
This is my first time ever using a pic and I'm not that familiar with embedded systems in general. I have used this website as my reference for how to initalize the lcd screen http://joshuagalloway.com/lcd.html.
Rich (BB code):
void write_lcd_4(unsigned char hex){
//set enable to low
PORTBbits.RB6 = 0;
//set r/s to zero for command
PORTBbits.RB4 = 0;
//put in high byte
PORTBbits.RB0 = getBit(hex, 0);
PORTBbits.RB1 = getBit(hex, 1);
PORTBbits.RB2 = getBit(hex, 2);
PORTBbits.RB3 = getBit(hex, 3);
//set enable high
PORTBbits.RB6 = 1;
//kill time
Delay10KTCYx(3);
//set enable to low for signal send
PORTBbits.RB6 = 0;
Delay10KTCYx(15);
}
void write_lcd(unsigned char hex){
//set enable to low
PORTBbits.RB6 = 0;
//set r/s to zero for command
PORTBbits.RB4 = 0;
//put in high byte
PORTBbits.RB0 = getBit(hex, 4);
PORTBbits.RB1 = getBit(hex, 5);
PORTBbits.RB2 = getBit(hex, 6);
PORTBbits.RB3 = getBit(hex, 7);
//set enable high
PORTBbits.RB6 = 1;
//kill time
Delay10KTCYx(3);
//set enable to low for signal send
PORTBbits.RB6 = 0;
Delay10KTCYx(15);
//put in low byte
PORTBbits.RB0 = getBit(hex, 0);
PORTBbits.RB1 = getBit(hex, 1);
PORTBbits.RB2 = getBit(hex, 2);
PORTBbits.RB3 = getBit(hex, 3);
/************************************************/
//set enable high
PORTBbits.RB6 = 1;
//kill time
Delay10KTCYx(3);
//set enable to low for signal send
PORTBbits.RB6 = 0;
Delay10KTCYx(15);
}
void lcd_init(void){
Delay10KTCYx(60);
write_lcd_4(0x03);
write_lcd_4(0x03);
write_lcd_4(0x03);
write_lcd_4(0x02);
//function set
write_lcd(0x28);
//turn off
write_lcd(0x08);
//display clear
write_lcd(0x01);
//entry mode
write_lcd(0x06);
//turn back on
write_lcd(0x09);
}