LCD tc1602a not able to display anything with Pic18f4520

Status
Not open for further replies.

caramelz

Junior Member level 2
Joined
Jul 19, 2012
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,464
Hi guys, my pic18f4520 have a crystal circuit of 20mhz.
connections
DB4 to RD0
DB5 to RD1
DB6 to RD2
DB7 to RD3
RA1 to E
RA2 to R/W
RA3 to RS
LCD pin 1 to Gnd
LCD pin 2 to +5V
LCD pin 3 to GND

Please tell me what is wrong here. Is any resistor needed?

Here is the code:

//20MHZ OSCILLATOR

#include <p18f4520.h>
#include <delays.h>

void Init_LCD(void); // Initialize the LCD
void W_ctr_4bit(char); // 4-bit Control word for LCD
void W_data_4bit(char); // 4-bit Text Data for LCD

#define LCD_DATA PORTD
#define LCD_RW PORTAbits.RA2
#define LCD_RS PORTBbits.RA3
#define LCD_E PORTBbits.RA1

unsigned char LCD_TEMP,i;
const rom char MESS[12]="ECAPP LAB3";

void main()
{
ADCON1=0x0f;
TRISA=0b11110001;
TRISD=0;
W_ctr_4bit(0b00000001);
for(i=0;i<MESS;i++)
W_data_4bit(MESS);
while(1);
}

void Init_LCD()
{ /* LCD display initialization */
// Special Sequence a) to d) required for 4-bit interface
Delay1KTCYx(75); // a) 15ms LCD power-up delay
W_ctr_4bit(0x03); // b) Function Set (DB4-DB7: 8-bit interface)
Delay1KTCYx(25); // c) 5ms delay
W_ctr_4bit(0x02); // d) Function Set (DB4-DB7: 4-bit interface)
W_ctr_4bit(0b00101000); // Function Set - 4-bit, 2 lines, 5X7
W_ctr_4bit(0b00001100); // Display on, cursor off
W_ctr_4bit(0b00000110); // Entry mode - inc addr, no shift
W_ctr_4bit(0b00000001); // Clear display & home position
}

void W_ctr_4bit(char x)
{
LCD_RW=0;
LCD_RS=0;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(5);
LCD_E=0;
Delay1KTCYx(5);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD TEMP;
Delay1KTCYx(5);
LCD_E=0;
Delay1KTCYx(5);
}

void W_data_4bit(char x)
{
LCD_RW=0;
LCD_RS=1;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(5);
LCD_E=0;
Delay1KTCYx(5);
LCD_TEMP=x;
LCD_TEMP&=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(5);
LCD_E=0;
Delay1KTCYx(5);
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…