#include <LPC214X.H>
//Control lines connected to P0.0, P0.1, P0.2, nad data is connected to P0.4,P0.5, P0.6, P0.7 #define LCD_DATA 0x000000FF #define LCD_SET IO0SET #define LCD_CLR IO0CLR //Control lines connected to P0.4, P0.5, P0.6, P0.7 //#define CTRL 0x000000 //#define CTRL_SET IOSET1 //#define CTRL_CLR IOCLR1
#define RS 0x00000001; /* Set P0.0 */ #define WR 0x00000002; /* Set P0.1 */ #define EN 0x00000004; /* Set P0.2 */
#define LCDRS (1 << 0) #define LCDRW (1 << 1) #define LCDEN (1 << 2)
#define LCD_D4 (1 << 4) #define LCD_D5 (1 << 5) #define LCD_D6 (1 << 6) #define LCD_D7 (1 << 7)
#define LCD_DATA_MASK (LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7) //-------------------fuction declations----------------------- void LcdInit (void); void LcdData (unsigned char data); void LcdCmd (unsigned char cmd); void delay_lcd(void); //void DisplayRow (int row, char *str); void int_port(void); void delay1(unsigned int); void delay(int count); //------------------------------------------------------------------------------
int main () { int_port(); LcdInit(); LcdData('A'); LcdData('B'); LcdData('C'); while(1); } void int_port(void) { PINSEL0=0x00000000; PINSEL1=0x00000000; IO0DIR = LCD_DATA; LCD_SET=(LCDRS | LCDRW | LCDEN); LCD_CLR|=LCD_DATA_MASK; //All segments Off //CTRL_SET= CTRL; // LCD_CLR = LCD_DATA; //All segments Off } //---------------------------------lcd initi-------------------------- void LcdInit (void) {
delay1(5); delay1(5); delay1(5);
LcdCmd(0x01); // LCD clear LcdCmd(0x03); // commands from datasheet delay1(5); LcdCmd(0x03); delay1(5); LcdCmd(0x03); delay(100); LcdCmd(0x28); // Select nibble mode LcdCmd(0x06); // LCD diaply and cursor ON LcdCmd(0x0e); // cursor diraction and link // LcdCmd(0x10); LcdCmd(0x01); // clear LCD
} //-------------------------------------------------------------------- void delay1(unsigned int time ) // delay in ms { int i,j; for (i=0;i<=time;i++) for (j=0;j<=5000;j++); } //--------------------------------------------------------------------- void LcdCmd (unsigned char cmd) { int temp1;
temp1 = cmd; temp1 &= 0x000000f0; // get higher nibble
LCD_CLR= LCD_DATA; // Clear LCD data IO0PIN = temp1; // Send data on port 0
LCD_CLR= RS; // clear RS pin LCD_CLR= WR; // clear wr pin
LCD_SET=EN; // set anable pin delay(5); LCD_CLR=EN; // clear enable pin delay(10);
temp1=cmd; temp1=temp1<<4; // rotate data right temp1 &=0x000000f0; // get lower nibble
LCD_CLR= RS; LCD_CLR= WR;
LCD_SET=EN; delay(5); LCD_CLR=EN; delay(10); } //--------------------------------------------------------------------------------------------------------------- void LcdData (unsigned char data) { int temp1;
temp1 = data; temp1 &= 0x000000f0; // get higher nibble
LCD_SET= RS; // set RS pin LCD_CLR= WR; //set wr pin
LCD_SET=EN; delay(5); LCD_CLR=EN; delay(10);
temp1=data; temp1=temp1<<4; // rotate data right temp1 &=0x000000f0; // get lower nibble
LCD_CLR= LCD_DATA; IO0PIN = temp1;
LCD_SET= RS; LCD_CLR= WR; LCD_SET=EN; delay(5); LCD_CLR=EN; delay1(5); } //------------------------------------------------------------------------------ void delay_lcd(void) // small delay { int j; for (j=0;j<600;j++); }
//------------------------------------------------------------------------------------ void delay(int count) { int j=0,i=0;
for(j=0;j<count;j++) { /* At 60Mhz, the below loop introduces delay of 10 us */ for(i=0;i<35;i++); } } //-----------------------------------------------------------------------------------
I have a doubt about that my delay routine are not generating correct delay.
Thank u, Heena
That's exactly why you should never write delay routines in any High-Level Language(HLL) - See: www.8052.com/.../162556
You also missed the clear instructions on how to post source code: www.danlhenry.com/.../keil_code.png
If you can miss something that obvious, then you should also go back and carefully re-check your processor & LCD documentation to see if there's any other important detais that you missed there...?
ok sir , i will again send my code , and i have check my LCD document also the commands are correct and some i have used with 8 bit display also, there it is working nice with same cammand , data and delay routine.The LCD which i am using is 44780 LCD.
Thank u, Heena Panchal
Below is my source code
#include <LPC214X.H> //Control lines connected to P0.0, P0.1, P0.2, nad data is connected to P0.4,P0.5, P0.6, P0.7 #define LCD_DATA 0x000000FF #define LCD_SET IO0SET #define LCD_CLR IO0CLR //Control lines connected to P0.4, P0.5, P0.6, P0.7 //#define CTRL 0x000000 //#define CTRL_SET IOSET1 //#define CTRL_CLR IOCLR1 #define RS 0x00000001; /* Set P0.0 */ #define WR 0x00000002; /* Set P0.1 */ #define EN 0x00000004; /* Set P0.2 */ #define LCDRS (1 << 0) #define LCDRW (1 << 1) #define LCDEN (1 << 2) #define LCD_D4 (1 << 4) #define LCD_D5 (1 << 5) #define LCD_D6 (1 << 6) #define LCD_D7 (1 << 7) #define LCD_DATA_MASK (LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7) //-------------------fuction declations----------------------- void LcdInit (void); void LcdData (unsigned char data); void LcdCmd (unsigned char cmd); void delay_lcd(void); //void DisplayRow (int row, char *str); void int_port(void); void delay1(unsigned int); void delay(int count); //------------------------------------------------------------------------------ int main () { int_port(); LcdInit(); LcdData('A'); LcdData('B'); LcdData('C'); while(1); } void int_port(void) { PINSEL0=0x00000000; PINSEL1=0x00000000; IO0DIR = LCD_DATA; LCD_SET=(LCDRS | LCDRW | LCDEN); LCD_CLR|=LCD_DATA_MASK; //All segments Off //CTRL_SET= CTRL; // LCD_CLR = LCD_DATA; //All segments Off } //---------------------------------lcd initi-------------------------- void LcdInit (void) { delay1(5); delay1(5); delay1(5); LcdCmd(0x01); // LCD clear LcdCmd(0x03); // commands from datasheet delay1(5); LcdCmd(0x03); delay1(5); LcdCmd(0x03); delay(100); LcdCmd(0x28); // Select nibble mode LcdCmd(0x06); // LCD diaply and cursor ON LcdCmd(0x0e); // cursor diraction and link // LcdCmd(0x10); LcdCmd(0x01); // clear LCD } //-------------------------------------------------------------------- void delay1(unsigned int time ) // delay in ms { int i,j; for (i=0;i<=time;i++) for (j=0;j<=5000;j++); } //--------------------------------------------------------------------- void LcdCmd (unsigned char cmd) { int temp1; temp1 = cmd; temp1 &= 0x000000f0; // get higher nibble LCD_CLR= LCD_DATA; // Clear LCD data IO0PIN = temp1; // Send data on port 0 LCD_CLR= RS; // clear RS pin LCD_CLR= WR; // clear wr pin LCD_SET=EN; // set anable pin delay(5); LCD_CLR=EN; // clear enable pin delay(10); temp1=cmd; temp1=temp1<<4; // rotate data right temp1 &=0x000000f0; // get lower nibble LCD_CLR= LCD_DATA; // Clear LCD data IO0PIN = temp1; // Send data on port 0 LCD_CLR= RS; LCD_CLR= WR; LCD_SET=EN; delay(5); LCD_CLR=EN; delay(10); } //--------------------------------------------------------------------------------------------------------------- void LcdData (unsigned char data) { int temp1; temp1 = data; temp1 &= 0x000000f0; // get higher nibble LCD_CLR= LCD_DATA; // Clear LCD data IO0PIN = temp1; // Send data on port 0 LCD_SET= RS; // set RS pin LCD_CLR= WR; //set wr pin LCD_SET=EN; delay(5); LCD_CLR=EN; delay(10); temp1=data; temp1=temp1<<4; // rotate data right temp1 &=0x000000f0; // get lower nibble LCD_CLR= LCD_DATA; IO0PIN = temp1; LCD_SET= RS; LCD_CLR= WR; LCD_SET=EN; delay(5); LCD_CLR=EN; delay1(5); } //------------------------------------------------------------------------------ void delay_lcd(void) // small delay { int j; for (j=0;j<600;j++); } //------------------------------------------------------------------------------------ void delay(int count) { int j=0,i=0; for(j=0;j<count;j++) { /* At 60Mhz, the below loop introduces delay of 10 us */ for(i=0;i<35;i++); } } //-----------------------------------------------------------------------------------
That's better - wasn't so hard, was it?
But you haven't checked your code very carefully:
temp1 &= 0x000000f0; // get higher nibble
and
temp1 &=0x000000f0; // get lower nibble
Can't both be right - can they?!
And you still have a software delay loop:
you should never write delay routines in any High-Level Language(HLL) - See: www.8052.com/.../162556
Sir,
The second time which i have mentioned as "read lower nibble" is after shifting the data.
Can u pls help me to write correct delay routine or i should use timer for delay generation..