Skip navigation
TechXchange
Digi-Key TechXchange Communities > Projects and Designs > Discussions
5880 Views 1 Reply Latest reply: 30/06/2011 1:57 PM by Robert Nelson RSS
Currently Being Moderated

30/06/2011 6:47 AM

LCD initialization, using CCS4 and EM430F6137RF900

Hello,

 

I’m trying to initialize an lcd display. The lcd is doing something strange when I run the code then turn the power on an off on the lcd the code will perform the last instruction only. For example I if I try to display “Hello”, the “o” will repeat randomly sometimes on the second like a couple of “o’s” sometimes on the top. Again this is running the code and then clicking the power on an off the lcd. I’ve also tried different delays. Any help at all would be highly appreciated; it seems that I have tried everything and nothing it fixing this issue.

 

Hardware: EM430F6137RF900, lcd: http://www.lumex.com/specs/LCR-U01602DSF+D-WH.pdf

 

Software: Code Composer Studio v4

 

Code:

 

#include <stdio.h> // standard library

 

#include "cc430f6137.h" //cc430f6137 library

 

void latch ();

 

 

 

void main()

 

{

 

      P4DIR = 0xFF; //ALL PORT 4 OUT

 

      P3DIR = 0x07; //3.0, 3.1, 3.2 PORT 3 OUT

 

      P3OUT = 0x00; //SET ENABLE OFF, SET RS and RW OFF

 

      //POWER ON

 

      __delay_cycles(1);

 

      P4OUT = 0x30; //STEP1 - Wake up

 

      latch();

 

      __delay_cycles(1);

 

      P4OUT = 0x30; //STEP2 - Wake up

 

      latch();

 

      __delay_cycles(1);

 

      P4OUT = 0x30; //STEP3 - Wake up

 

      latch();

 

      __delay_cycles(1); //STEP4 - Function set

 

      P4OUT = 0x38;

 

      latch();

 

      __delay_cycles(1); //STEP5 - Display off

 

      P4OUT = 0x10;

 

      latch();

 

      P4OUT = 0x0C; //STEP6 - Display clear

 

      latch();

 

      P4OUT = 0x06; //STEP7 - Entry mode set

 

      latch();

 

      P4OUT = 0x0F;     //Set cursor to blink

 

      latch();

 

}

 

void latch ()

 

{

 

      P3OUT ^= 0x04; //on

 

      __delay_cycles(1);

 

      P3OUT ^= 0x04;    //off

 

}

  • Robert Nelson designspecialist-micro 70 posts since
    21/03/2011

    Hi Giselle,

     

    Based on your code snippet, it looks as though you aren't polling the lcd's Busy Flag after the device has woken up.  So you may be overloading the device, hence the random character errors.

     

    So before every lcd command/data write (in your case, starting with first "STEP4" in your code) you really should check the busy flag..

     

    Here's a quick example/code snippet from one of my lcd libraries.

     

    #define LCD_DATA_BF (1 << 7)
    
    unsigned char lcd_getaddr(void)
    {
      unsigned char address;
    
      //Set Data Lines as Input
      LCD_DATA_DDR = 0;
    
      //Strobe the RW and E lines
      LCD_CTRL_PORT |= (LCD_CTRL_RW | LCD_CTRL_E);
    
      _delay_us(5);
    
      //Read the LCD Data Lines
      address = LCD_DATA_PIN;
    
      //Reset the RW and E lines
      LCD_CTRL_PORT &= ~(LCD_CTRL_RW | LCD_CTRL_E);
    
      return address;
    }
    
    void lcd_wait_bf(void)
    {
      while ((lcd_getaddr() & LCD_DATA_BF) == LCD_DATA_BF)
    }
    

     

    Regards,

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 3 points