#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
because the real LCD depends upon the correct timing - doesn't it?
One of the things that the simulator doesn't observe is timing.
And, of course, the simulator also won't be aware of any other hardware issues on your target...
Sir,
As i mentioned earlier my code with 8 bit data is working , but when i used the same code for nibble mode it is not working,
As per LCD datasheet the only difference is that we have to write command 0x28 instead of 0x38 and the higher nibble is send fisrt and then lower nibble; and we have to toggle enable bit every time we write data..
More to the point, you have to toggle the enable bit with the correct timing every time you write data...
/* At 60Mhz, the below loop introduces delay of 10 us */ for(i=0;i<35;i++);
Are you _really_ sure that your look takes 10us? 600 instruction cycles to count 35 ticks?
Now, please inform us exactly how you have validated the above code. Did you use an oscilloscope or exactly what did you do?
Have you also tried to change the optimization settings for the compiler? How did that change the length of the delay?
What was your conclusions from the above tests?
Dear Sir,
I am very new to ARM7 programming and i have taken this delay code from one of my mate, i have not actully count the instruction cycles...
pls guide me for better delay routine...
This has absolutely nothing whatsoever to do with ARM7 - it is inherent in the very nature of any High-Level Language (HLL)!
"pls guide me for better delay routine"
I have already given you a link - twice - that explains the issue!
Look at http://www.keil.com/forum/14875/
There you will find a good working software delay routine.
Thank u so much sir my LCD is now working fine...
Thank u sir for your advise..