AnsweredAssumed Answered


Question asked by travrt travrt on Mar 17, 2009
Latest reply on Jan 10, 2010 by J J

I have a DEMOQE board and I'm trying to drive an LCD with.  I'm having problems initializing it in 4-bit mode.  I've gone over the HD44780U datasheet, over and over and still could use some help.


I know I don't have any delays in there, as I have been stepping thru it in the simulator.  Also I'm not sure if I'm suppose to strobe the Enable line at the initial passing of 0x03 three times?  Either way it doesn't work.



#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations *//* Define a shortname for variable types */ typedef unsigned char    UINT8;  /*  8 bits */typedef unsigned short int UINT16; /* 16 bits */typedef unsigned long int  UINT32; /* 32 bits */typedef signed char     INT8;   /*  8 bits */typedef signed short int  INT16;  /* 16 bits */typedef signed long int   INT32;  /* 32 bits */typedef volatile UINT8   VUINT8;  /*  8 bits */typedef volatile UINT16   VUINT16; /* 16 bits */typedef volatile UINT32   VUINT32; /* 32 bits */#define LCD_STROBE_E ((PTCD_PTCD6 = 1),(PTCD_PTCD6=0));//Register select line#define LCD_RSH (PTCD_PTCD4= 1);#define LCD_RSL (PTCD_PTCD4= 0);//Read/Write#define LCD_RWH (PTCD_PTCD5= 1);#define LCD_RWL (PTCD_PTCD5= 0);//Enable line#define LCD_EH (PTCD_PTCD6 = 1);#define LCD_EL (PTCD_PTCD6 = 0);void initLCD(void), LCDCmd(UINT8), LCDChar(UINT8), dsplyString(UINT8 *), chkLCDbusy(void);void delay(int);void main(void) {  initLCD();  LCDChar('a');  while(1){           }   }/***************************  LCD Connections  ****************************4-bit modePTC0-PTC3 = DB4-DB7   Data busPTC4      = RS        Register selectPTC5      = R/W       Read / WritePTC6      = E         EnablePORTC 0b00000000         |||||||         |||---- data bus  0x0F         |||---- RS        0x10         ||----- R/W       0x20         |------ Enable    0x40  */        /***************************  Initialization of LCD  ************************/void initLCD(void) {     PTCDD = 0xFF; //Set PortC as output    PTCD = 0x00;  //Set PortC outputs to 0x00        PTCD=0x03;        PTCD=0x03;            PTCD=0x03;                    LCDCmd(0x28);        LCDCmd(0x08);    LCDCmd(0x01);    LCDCmd(0x06);    LCDCmd(0x0C);  }/****************************  LCD Commands  ****************************//*0x01;    clears screen0x38; sets up the display initalization0x0F; turns display on0x06; sets the cursor on and blinking0x02; move cursor to start and don't destroy data0x18;  shifts cursor to the left when a char is entered0x1C;  shifts cursor to the right when a char is entered0x10;    moves 1 char to the left0x14;    moves 1 char to the right0x80; add this to the address of the display to set the cursor position wanted*/void LCDCmd(UINT8 ch) {    UINT8 ln, un;    //lower and upper nibble    ln = ch & 0x0F;    un = ch >>4;    //chkLCDbusy();        PTCD = un;    LCD_EH;    LCD_EL;       PTCD = ln;    LCD_EH;    LCD_EL;}/**********************  Places a Char on LCD screen  ***********************/void LCDChar(UINT8 ch) {    UINT8 ln, un;    //lower and upper nibble    ln = ch & 0x0F;    un = ch >>4;        //chkLCDbusy();            PTCD = un;    LCD_EH;    LCD_EL;    PTCD = ln;    LCD_EH;    LCD_EL;            }/************************  Places a String on LCD screen  ********************/void dsplyString(UINT8 *msgptr) {  do    {    LCDChar( *msgptr);  }while( *msgptr++ != 0);}/**************************  Checks the LCD Busy line  **********************/void chkLCDbusy(void){    PTCDD = 0xF0;        //make PTC an input    LCD_RWH;               //read mode  while((PTCD & 0x08) == 0x08){;}      PTCD = 0x00;        PTCDD = 0xFF;        //make porta an output }//delay codevoid delay(int cnt)     //accepts value for the amount of delay wanted{ int i;  for(i=0;i<cnt;i++){  }}