Hi Everyone,
i have written code for interfacing LCD With lpc2103 Microcontroller.i have interfaced it with 8 bit mode. i tried to debug the problem but not successful.acually the problem is while sending data or command to lcd i am getting perfect on LCD pins but nothing on LCD Disply. Below i have shown my code can anybody figureout why this problem occurs. MY LCD Controller is KS006U.
#include "LPC2103.h"
#define Lcd_Command 0 #define Lcd_Data 1
#define Lcd_Db0 0x00020000 #define Lcd_Db1 0x20000000 #define Lcd_Db2 0x10000000 #define Lcd_Db3 0x00000800 #define Lcd_Db4 0x01000000 #define Lcd_Db5 0x00000400 #define Lcd_Db6 0x00200000 #define Lcd_Db7 0x00100000
#define Lcd_Rs 0x02000000 #define Lcd_Rw 0x00080000 #define Lcd_En 0x00010000
#define Lcd_Io_All (Lcd_Db0|Lcd_Db1|Lcd_Db2|Lcd_Db3|Lcd_Db4|Lcd_Db5|Lcd_Db6|Lcd_Db7|Lcd_Rs|Lcd_Rw|Lcd_En) #define Lcd_Db_All (Lcd_Db0|Lcd_Db1|Lcd_Db2|Lcd_Db3|Lcd_Db4|Lcd_Db5|Lcd_Db6|Lcd_Db7)
void Delay50ms(unsigned char val);
void init() {
PINSEL0 |= 0x00000000; PINSEL1 |= 0x00000000; IODIR |= Lcd_Io_All; // Set Directions as an output port. IOCLR = Lcd_Io_All; } void Lcd_Busy() { IODIR &= 0xFFEFFFFF; //Set Db7 bit as input port IOCLR = Lcd_Rs; IOSET = Lcd_Rw; while(IOPIN & Lcd_Db7) { IOSET = Lcd_En; Delay50ms(1); IOCLR = Lcd_En; Delay50ms(1); } } void Send_Lcd(unsigned char command_data, unsigned char dat ) {
IODIR = Lcd_Io_All; IOCLR = Lcd_Db_All; if(dat & 0x01) { IOSET = Lcd_Db0; } if(dat & 0x02) { IOSET = Lcd_Db1; } if(dat & 0x04) { IOSET = Lcd_Db2; } if(dat & 0x08) { IOSET = Lcd_Db3; } if(dat & 0x10) { IOSET = Lcd_Db4; } if(dat & 0x20) { IOSET = Lcd_Db5; } if(dat & 0x40) { IOSET = Lcd_Db6; } } if(dat & 0x80) { IOSET = Lcd_Db7; } //Delay50ms(1);
if(Lcd_Command == command_data) { IOCLR = Lcd_Rs; // RS = 0 for command } if(Lcd_Data == command_data) { IOSET = Lcd_Rs; // RS = 1 for data }
IOCLR = Lcd_Rw; // r/w ,w =0 for write IOSET = Lcd_En; // En pin H to L transition. Delay50ms(1); IOCLR = Lcd_En; //Delay50ms(2); Lcd_Busy(); } void Delay50ms(unsigned char val) { unsigned int j;unsigned char i,val1; for(;val>0;val--)
for(val1=5;val1>0;val1--) { for(j=0;j<1623;j++) { for(i=10;i>=1;i--); } }
} int main() { unsigned char i; char array[] = "Dhaval"; init(); Delay50ms(4); Send_Lcd(Lcd_Command,0x38); //8 bit,2 line,5x7 dots Send_Lcd(Lcd_Command,0x0e); //set display and cursor Send_Lcd(Lcd_Command,0x01); // clear the display Send_Lcd(Lcd_Command,0x06); // Entry Mode Set Send_Lcd(Lcd_Command,0x80); // Return Home while(1)
{ for(i=0;i<=5;i++) { Send_Lcd(Lcd_Data,array[i]); } Delay50ms(60);
Send_Lcd(Lcd_Command,0x01); // clear the display Send_Lcd(Lcd_Command,0x02); // Return Home } }