This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

20x4 line 8 - Bit mode LCD interfacing Using MSP430F2618

Other Parts Discussed in Thread: MSP430F2618

Hi,

I want to interface a 20x4 line LCD to my MSP430F2618 microcontroller.. I wrote a code but it didn't work what problem with my code.

wheather the code is correct or wrong?the LCD show wrong display..

Thanks in Advance

Joseph.D

My code is below....



   

/*********************************************
 Header File Intialization
*********************************************/
#include  <msp430f2618.h>

/**********************************************
 * Defines
 * ********************************************/
#define     LCM_OUT                   P1OUT
#define        DATA_OUT                P2OUT

#define     LCM_PIN_RS                BIT6          // P1.0
#define     LCM_PIN_EN                BIT7          // P1.1

#define        KeyDebounceData            40
#define     KeyScanTimeOutData        20

#define     FALSE                 0
#define     TRUE                  1

#define VerifyHreg                0x12
#define VerifyLreg                0x34
/********************************************
 Variable Declaration
*********************************************/
unsigned char Msec1Reg;
unsigned int Sec1Reg,ProgramOkReg,OutputReg,ProgramNotOkReg,ProgramTestReg;
unsigned char DebounceReg,BlinkPosition;
unsigned char ReactionTimeDisplayReg;
unsigned char PasswordMsbHreg,PasswordMsbLreg,PasswordLsbHreg,PasswordLsbLreg,EditHreg,EditLreg;
unsigned char PassReg,PassHreg,PassLreg,KeyScanTimeOutReg;

/********************************************
 FlagDeclaration
*********************************************/
  struct
    {
        unsigned char    Msec1Flag  :1;
        unsigned char    Sec1Flag:1;
        unsigned char    SetKeyFlag :1;
        unsigned char    UpKeyFlag :1;
        unsigned char    DownKeyFlag :1;
        unsigned char    EnterKeyFlag :1;
        unsigned char    EscKeyFlag:1;
        unsigned char    OutputFlag:1;
        unsigned char    EditFlag:1;
        unsigned char    ErrorFlag:1;
        unsigned char    ProgramTestFlag:1;
        unsigned char    ProgramOkFlag:1;
        unsigned char     ProgramNotOkFlag:1;
        unsigned char    TimeOutFlag:1;
        unsigned char    TrFlag:1;
        
    }stat ;
/********************************************
 Function Declaration
********************************************/
void PowerOnHardwareInit(void);
void PowerOnRegInit(void);
void PowerOnFlagInit(void);
void KeyScan(void);
void PowerOnRead(void);
void PulseLcm();
void SendByte(char ByteToSend, int IsData);
void LcdGoto(unsigned char pos);
void ClearLcmScreen();
void InitializeLcm(void);
void PrintStr(char *Text);
void Putch(unsigned char a);

/*********************************************
 Main
*********************************************/
void main(void)
{
    
    PowerOnHardwareInit();
    PowerOnRegInit();
    PowerOnFlagInit();
    InitializeLcm();
    ClearLcmScreen();
    
    
 LcdGoto(0xC1);
    PrintStr("Hello");
   
 
    __delay_cycles(100000);


    while(1)
        {
        
            
        }
}
/***********************************************
 *HardwareInitialization
 * ********************************************/
void PowerOnHardwareInit()
    {
          BCSCTL1 = CALBC1_1MHZ;                        // Set range
          DCOCTL = CALDCO_1MHZ;                         // Set DCO step + modulation */
          WDTCTL = WDTPW + WDTHOLD;                     // Stop watchdog timer
          P2DIR= 0xFF;//0xF7//11111010
          P2SEL=0x00;
          P2OUT=0x00;
          
          P1DIR=0xF0;                           // CCR1 PWM duty cycle
          P1OUT=0xFF;
      //    P1OUT&=~0x02;
          P1SEL=0x00;
      
          P3DIR=0xFF;
          P3SEL=0x00;
          P3OUT=0x00;
          _BIS_SR(GIE);                 // Enter LPM0 w/ interrupt    
    }
/**********************************************
 *Flag Initialization
 * *******************************************/
void PowerOnFlagInit()
    {
        
    
        
    }
/***********************************************
 * Register Initialization
 * ********************************************/
void PowerOnRegInit()
    {
    
    }
    

/*************************************************
 * LCD Strobe
 * **********************************************/    
void PulseLcm()
{
   
    LCM_OUT &= ~LCM_PIN_EN;
    __delay_cycles(200);
    LCM_OUT |= LCM_PIN_EN;
    __delay_cycles(200);
    LCM_OUT &= (~LCM_PIN_EN);
    __delay_cycles(200);
}

/*************************************************
 * Sending a byte Function
 * **********************************************/
void SendByte(char ByteToSend, int IsData)
{
   
   // LCM_OUT =0x00;
    DATA_OUT = 0;
    
    DATA_OUT = (ByteToSend);
 
    if (IsData == TRUE)
    {
        LCM_OUT |= LCM_PIN_RS;
    }
    else
    {
        LCM_OUT &= ~LCM_PIN_RS;
    }
    PulseLcm();
}
/**************************************************
 * LCD Location Function
 * ***********************************************/
void LcdGoto(unsigned char pos)
{
    SendByte(pos, FALSE);
}
/*************************************************
 * LCD Clear Function
 * **********************************************/
void ClearLcmScreen()
{
    
    SendByte(0x01, FALSE);
    SendByte(0x02, FALSE);
    __delay_cycles(200);
}
/*************************************************
 * Cursor On  Function
 * **********************************************/
void CursorOn()
{
    LcdGoto(0xC0+BlinkPosition);
    SendByte(0x0F, FALSE);
}
/*************************************************
 * Cursor Off Function
 * **********************************************/
void CursorOff()
{
    
    SendByte(0x0C, FALSE);
}
/*************************************************
 * LCD Initialization
 * **********************************************/
void InitializeLcm(void)
{
    
     LCM_OUT = 0x00;
     DATA_OUT = 0x00;

    __delay_cycles(100000);

    
    LCM_OUT &= ~LCM_PIN_RS;
    LCM_OUT &= ~LCM_PIN_EN;

   
    PulseLcm();

    SendByte(0x38, FALSE);
      __delay_cycles(20000);
     SendByte(0x38, FALSE);
       __delay_cycles(20000);
      SendByte(0x38, FALSE);
      __delay_cycles(20000);
       SendByte(0x0C, FALSE);
        __delay_cycles(20000);
       SendByte(0x06, FALSE);;
}
/*************************************************
 * LCD Print Function
 * **********************************************/
void PrintStr(char *Text)
{
    char *c;

    c = Text;

    while ((c != 0) && (*c != 0))
    {
        SendByte(*c, TRUE);
        c++;
    }
}
/***************************************************
 * LCD Character Include Function
 * ************************************************/
void Putch(unsigned char a)
{
    SendByte(a,TRUE);
}

**Attention** This is a public forum