Jump to content
Karteek

Interfacing 16x2 LCD with Stellaris Launchpad EK-LMF120XL

Recommended Posts

Hi

 

Started Working with Stellaris Launchpad  EK-LMF120XL,I tried Interfacing with LED and now started with  LCD.

 

I am trying to print a single character,I unable to do it,i am posting my code please have a look .tell me  where i

 

am going wrong,

 

 

Thanks and Regards

     Karteek

 

 

LCD code for single character

 

 

 

#include "lm4f120h5qr.h"
 
/* Enable/Disable  Pin */
 
#define LCD_Enable  GPIO_PORTC_DATA_R|0x40; // To Enable LCD//
#define LCD_Disable() GPIO_PORTC_DATA_R&(~0x40);// To Disable LCD//
 
/*  Read Write Pin (R/W)  */
 
#define LCD_Enable_Read() GPIO_PORTC_DATA_R|0x20; // To Enable LCD Read Operation//
#define LCD_Enable_write GPIO_PORTC_DATA_R&(~0x20); // To Enable LCD Write Operation//
 
 
/* Pin RS (Register Select)*/
 
#define LCD_Enable_Display_Data() GPIO_PORTC_DATA_R|0x10; // When this signal is '1' = It accepts data to be displayed/
 
// When this signal is '0' = It accepts instructions for the LCD like setting font, cursor position etc//
#define LCD_Enable_instruction GPIO_PORTC_DATA_R&(~0x10); 
 
 
void portB_init();
void portC_init();
void write_LCD();
void Delay();
void latch();
int main()
{
  portB_init();// Initialization of port B//
  portC_init();// Initialization of port C//
  write_LCD();
  return 0;
}
 
void portB_init()
{
//  SYSCTL_GPIOHBCTL_R|=0X2u;
  SYSCTL_RCGCGPIO_R|=0x2u;
  GPIO_PORTB_DIR_R=0xFFu;
  GPIO_PORTB_DR8R_R|=0xFFu;
  GPIO_PORTB_DEN_R=0xFFu;
  
}
 
void portC_init()
{
  //SYSCTL_GPIOHBCTL_R|=0x04u;
SYSCTL_RCGCGPIO_R|=0x4u;
GPIO_PORTC_DIR_R=0x70u;
GPIO_PORTC_DR8R_R|=0x70u;
GPIO_PORTC_DEN_R=0x70u;
 
}
  
void write_LCD()
{
  int i=0;
  LCD_Enable_instruction;
  LCD_Enable_write;
  LCD_Enable;
  Delay();
  GPIO_PORTB_DATA_R=0x38u;  //This instruction will Enable 8-bit Databus, Set 2 lines, and Select font size 5x7//
  for(i=0;i<4;i++)
  {
    latch();
  }
  GPIO_PORTB_DATA_R=0x0fu;//It will display the characters, will display the cursor and it will blink.//
  latch();
  GPIO_PORTB_DATA_R=0x01u;// clear the entire display. And bring your cursor to position 0. Or home position.//
  latch();
  GPIO_PORTB_DATA_R=0x80u;// to select line 1//
  LCD_Enable_Display_Data();
  GPIO_PORTB_DATA_R=0x30u;//data to display //
  latch();
}  
  void latch()
  {
    LCD_Enable;
    Delay();
    LCD_Disable();
    Delay();
  }
 
void Delay()
{
  int count=0;
  while(count<10000000)
  {
    count++;
  }
}

Share this post


Link to post
Share on other sites

There is at least one library/example of using a character LCD with the Stellaris LP on the forums here.

http://forum.stellarisiti.com/topic/384-simple-hd44780-library-without-driverlib/

 

Your macros just read some of the registers - you probably want to make some of them write registers.

 

You might consider using some of the available libraries for basic I/O (e.g. Stellarisware, Energia) to make more readable code.

(Raw register access makes it really easy to make write-only code. - i.e. hard to read)

 

Edit: One other thought - suggest you use the code attribute when posting code here.

(It is hidden under the icon that looks like two angle braces - totally inobvious icon, but it does make code easier to read/recognize).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×