I have written a program for driving lCDusing 89S52 using keil . It is working in simulation but not displaying any thing on the target board In that program I have inserted a led blink code for knowing the program running status.The led is blinking means the code I have written is working .Then whats happening to my LCD part. Please any body suggest something.The crystal is 11.0592Mhz .....My code below
//delay.h// #ifndef __DELAY_H__ #define __DELAY_H__ void delay_us(unsigned int ); void delay_ms(unsigned int ); void delay_sec(unsigned char); void lcd_reset(); void LCD_Init(); void LCD_CmdWrite( char ); void LCD_DataWrite( char ); void LCD_GoToLineOne(); void LCD_GoToLineTwo(); void LCD_CmdWrite( char ); void LCD_GoToXY(char , char ); void LCD_DisplayString(char *string_ptr); void LCD_DisplayNumber(unsigned int ); void LCD_ScrollMessage(char *msg_ptr);
#endif
//delay.c// #include<reg52.h> /*---------------------------------------------------------------------------------- delay_us() void delay_us(unsigned int us_count) { while(us_count!=0) { us_count--; } } void delay_ms(unsigned int ms_count) { while(ms_count!=0) { delay_us(112); //delay_us is called to generate 1ms delay ms_count--; } }
void delay_sec(unsigned char sec_count) { while(sec_count!=0) { delay_ms(1000); //delay_ms is called to generate 1sec delay sec_count--; } } //D4-P0.4,D5-P0.5,D6-P0.6,D7-P0.7,RS-P0.0,RW-P0.1,EN-P0.2, #include<reg52.h> #include <delay.h> #define databus P2 // LCD databus connected to PORT2 sbit rs= databus^0; // Register select pin connected to P0.0 sbit rw= databus^1; // Read Write pin connected to P0.1 sbit en= databus^2; // Enable pin connected to P0.2 /* 16x2 LCD Specification */ #define LCDMaxLines 2 #define LCDMaxChars 16 #define LineOne 0x80 #define LineTwo 0xc0 #define BlankSpace ' ' void lcd_reset() { databus = 0xFF; delay_ms(20); databus = 0x34; databus = 0x30; delay_ms(10); databus = 0x34; databus = 0x30; delay_ms(1); databus = 0x34; databus = 0x30; delay_ms(1); databus = 0x24; databus = 0x20; delay_ms(1); } void LCD_Init() { //delay_us(5000); lcd_reset(); LCD_CmdWrite(0x02); //Initilize the LCD in 4bit Mode LCD_CmdWrite(0x28); LCD_CmdWrite(0x0E); // Display ON cursor ON LCD_CmdWrite(0x01); // Clear the LCD LCD_CmdWrite(0x80); // Move the Cursor to First line First Position }
void LCD_CmdWrite( char cmd) { databus=(cmd & 0xf0); // Send the Higher Nibble of the command to LCD rs=0; // Select the Command Register by pulling RS LOW rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin delay_us(1); en=0; delay_us(10); // wait for some time databus=((cmd<<4) & 0xf0); // Send the Lower Nibble of the command to LCD rs=0; // Select the Command Register by pulling RS LOW rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin delay_us(1); en=0; delay_ms(1); } void LCD_DataWrite( char dat) { databus=(dat & 0xf0); // Send the Higher Nibble of the Data to LCD rs=1; // Select the Data Register by pulling RS HIGH rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin delay_us(1); en=0; delay_us(10); // wait for some time. databus=((dat <<4) & 0xf0); // Send the Lower Nibble of the Data to LCD rs=1; // Select the Data Register by pulling RS HIGH rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin delay_us(1); en=0; delay_ms(1); } void LCD_DisplayString(char *string_ptr) { while(*string_ptr) LCD_DataWrite(*string_ptr++); } void LCD_DisplayNumber(unsigned int num) { LCD_DataWrite((num/10000)+0x30); num=num%10000; LCD_DataWrite((num/1000)+0x30); num=num%1000; LCD_DataWrite((num/100)+0x30); num=num%100; LCD_DataWrite((num/10)+0x30); LCD_DataWrite((num%10)+0x30); }
void LCD_ScrollMessage(char *msg_ptr) { unsigned char i,j; LCD_CmdWrite(0x0c); //Disable the Cursor for(i=0;msg_ptr[i];i++) //Loop to display the complete string { //each time 16 chars are displayed and //pointer is incremented to point to next char LCD_GoToLineOne(); //Move the Cursor to first line for(j=0; j<LCDMaxChars && msg_ptr[i+j];j++) //loop to Display first 16 Chars LCD_DataWrite(msg_ptr[i+j]); //or till Null char for(j=j; j<LCDMaxChars; j++) //If the chars are below 16 LCD_DataWrite(BlankSpace); //then display blank spaces delay_ms(125); } LCD_CmdWrite(0x0E); //Enable the Cursor } void LCD_GoToLineOne() { LCD_CmdWrite(LineOne); // Move the Cursor to First line First Position }
void LCD_GoToLineTwo() { LCD_CmdWrite(LineTwo); // Move the Cursor to Second line First Position }
void LCD_GoToXY(char row, char col) { char pos; if(row<LCDMaxLines) { pos= LineOne | (row << 6); // take the line number //row0->pos=0x80 row1->pos=0xc0 if(col<LCDMaxChars) pos= pos+col; //take the char number //now pos points to the given XY pos LCD_CmdWrite(pos); // Move the Cursor to specified Position } } //main.c// #include<reg52.h> #include <delay.h> main() { unsigned char k; LCD_Init() ; LCD_GoToLineOne(); LCD_DisplayString("**SUSHILA KUMAR**"); P1 = 255; while(1) { k = P1; delay_ms(250); P3 = 0; delay_ms(250); P3 = 255; LCD_GoToLineTwo(); LCD_DisplayNumber(k);
}
} kindly suggest me.........