pcsandhya82
Member level 3
Hi,
I m trying to do a simple LCD interface. controller is PIC18f4550, running on 20MHz crystal, LCD is JHD 162A, c18 compiler. Port B is used as data port, and port A as control. 10k pot for contrast setting of LCD. When I run the program, the first array of LCD lights up, and nothing else happens, no matter what command I have given. But the command voltages are available at LCD terminals.
Proteous simulation works fine.The code is as follows:
// Program to interface 16x2 LCD and display a single character using PIC18F4550
As troubleshooting, I attempted the following:
1)To see if the config bits are wrong, I wrote an LED flashing program for port A. Tested with LED s connected to port A, it worked fine.
2) Checked if the controller actually outputs the commands in the ports. Tried sending only 0x38 to PORTA. The ascii value of 0x38 (00111000) was appearing on PORTA when I executed the program. Verified this with multimeter, 5v for 1's and 0v for 0's.
3)To see if there is a problem with the LCD, I tried with another LCD. Same result.
Proteous design attached. Could someone please help?
I m trying to do a simple LCD interface. controller is PIC18f4550, running on 20MHz crystal, LCD is JHD 162A, c18 compiler. Port B is used as data port, and port A as control. 10k pot for contrast setting of LCD. When I run the program, the first array of LCD lights up, and nothing else happens, no matter what command I have given. But the command voltages are available at LCD terminals.
Proteous simulation works fine.The code is as follows:
// Program to interface 16x2 LCD and display a single character using PIC18F4550
Code:
#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS
#include<p18f4550.h>
#include"delay.h"
#define rs LATAbits.LATA0
#define rw LATAbits.LATA1
#define en LATAbits.LATA2
#define lcdport LATB
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned int i=0;
void lcd_ini()
{
lcdcmd(0x38); //16x2, 5x7matrix LCD.
lcdcmd(0x01); //CLEAR DISPLAY AND DDRAM CONTENT
lcdcmd(0x06); //ENTRY MODE
lcdcmd(0x0F); //DISPLAY ON, CURSOR BLINKING
}
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
DelayMs(10);
en=0;
}
void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
DelayMs(10);
en=0;
}
void main(void)
{
TRISA=0; // Configure Port A as output port
LATA=0;
TRISB=0; // Configure Port B as output port
LATB=0;
lcd_ini(); // LCD initialization
lcddata('H'); // Print 'H'
DelayMs(1000);
while(1);
}
As troubleshooting, I attempted the following:
1)To see if the config bits are wrong, I wrote an LED flashing program for port A. Tested with LED s connected to port A, it worked fine.
2) Checked if the controller actually outputs the commands in the ports. Tried sending only 0x38 to PORTA. The ascii value of 0x38 (00111000) was appearing on PORTA when I executed the program. Verified this with multimeter, 5v for 1's and 0v for 0's.
3)To see if there is a problem with the LCD, I tried with another LCD. Same result.
Proteous design attached. Could someone please help?
Attachments
Last edited by a moderator: