This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

My LCD routine doesnt work , simulator give correct answer

#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++); }
} //-----------------------------------------------------------------------------------

I have a doubt about that my delay routine are not generating correct delay.

Thank u,
Heena

Parents
  • 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..

Reply
  • 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..

Children