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.

Lcd interfacing

Other Parts Discussed in Thread: TM4C123GH6PM

#include <TM4C123gh6pm.h>

#define GPIO_PORTB_DATA_R (*((volatile unsigned long *)0x400053FC)) // bits 7-0 of port B
#define GPIO_PORTB_DIR_R (*((volatile unsigned long *)0x40005400))
#define GPIO_PORTB_AFSEL_R (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_DEN_R (*((volatile unsigned long *)0x4000551C))
#define GPIO_PORTB_AMSEL_R (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_DR8R_R (*((volatile unsigned long *)0x40005508))
#define GPIO_PORTB_PCTL_R (*((volatile unsigned long *)0x4000552C))

#define GPIO_PORTD_DATA_R (*((volatile unsigned long *)0x400073FC)) // bits 7-0
#define GPIO_PORTD_DIR_R (*((volatile unsigned long *)0x40007400))
#define GPIO_PORTD_AFSEL_R (*((volatile unsigned long *)0x40007420))
#define GPIO_PORTD_DEN_R (*((volatile unsigned long *)0x4000751C))
#define GPIO_PORTD_AMSEL_R (*((volatile unsigned long *)0x40007528))
#define GPIO_PORTD_PCTL_R (*((volatile unsigned long *)0x4000752C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))

#define RS(X) GPIO_PORTD_DATA_R = ((GPIO_PORTD_DATA_R & ~(1<<1))|(X<<1))
#define EN(X) GPIO_PORTD_DATA_R = ((GPIO_PORTD_DATA_R & ~(1<<3))|(X<<3))

#define databits GPIO_PORTB_DATA_R
#define LCD_STROBE do{EN(1);EN(0);} while(0)

#define lcd_display_data_1 "Stellaris |=====>"
#define lcd_display_data_2 "|=====> Launchpad"

#define LINE1 lcd_cmd(0x80)
#define LINE2 lcd_cmd(0xc0)

volatile unsigned long uloop;
//unsigned char string[16];

void setup()
{
    SYSCTL_RCGC2_R |= 0x0A;
uloop = SYSCTL_RCGC2_R;
GPIO_PORTB_AMSEL_R &= ~0xFF;
GPIO_PORTB_PCTL_R = 0x00000000;
GPIO_PORTB_DIR_R |= 0xFF;
GPIO_PORTB_AFSEL_R &= ~0xFF;
GPIO_PORTB_DR8R_R |= 0xFF;
GPIO_PORTB_DEN_R |= 0xFF;
    GPIO_PORTD_AMSEL_R &= ~0x0A;
GPIO_PORTD_PCTL_R &= 0x00000000;
GPIO_PORTD_DIR_R |= 0x0A;
GPIO_PORTD_AFSEL_R &= ~0x0A;
GPIO_PORTD_DEN_R |= 0x0A;
    
}
    void lcd_cmd(unsigned char c);
void lcd_data(unsigned char c);
void lcd_ready(void);
void sendString(char string[], unsigned int length);

void delay(unsigned int z)

{
    unsigned int i;

for(i=0;i<z;i++);
}

void sendString(char string[], unsigned int length)
{
unsigned int i;
for(i=0;i<length;i++)
{
lcd_data(string[i]);
}
}

void lcd_cmd(unsigned char c)
{
lcd_ready();

RS(0);
    databits=c;
EN(1);
delay(10);
EN(0);
}
void lcd_data(unsigned char c)
{
lcd_ready();

RS(1);
    databits=c;
EN(1);
delay(10);
EN(0);
}

void lcd_ready()
{
LCD_STROBE;
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0C);
    lcd_ready();
}    
int main()
{
while(1)
{
    setup();
    lcd_init ();
    LINE1;
    sendString(lcd_display_data_1, 16);
    LINE2;
    sendString(lcd_display_data_2, 16);
    RS(0);
}
}

this my code and its not working kindly help me

  • My friend - famed, "Not working" - while widely used - offers little insight to hapless helpers.
    If you perform a forum search keyed to cb1 & Lcd - multiple posts should reveal - surely these should aid your quest...
    At quick glance - your LCD initialization appears too brief - and too fast! Significant delays are required as the Lcd "awakes" after power up. Your search should uncover the HD44780 LCD Controller timing chart which I've long ago provided - right here. Wealth of info therein - happy searching....
  • Hello Ahmad

    As cb1 very wisely stated "Not working" is not the way to put forum posts. Describe what panel it is, how you are interfacing, what have you debugged so far. Also do check if connections are correct for signals and supply to the panel.

    Regards
    Amit
  • I dnt know how to calculate the delay. can u provide me a delay function that could manage the different delay as required by lcd functioning.

  • connections are correct. i am using 16x2 LCD. the issue is with delay i think, so can help me in delay calculation using frequency of 16 MHZ? which is by default frequency of tm4c123gh6pm.
  • ahmad hassan said:
    the issue is with delay i think

    As initially written here - that's absolutely true - yet "far more" issues (surely) lurk.

    Have you performed the search past suggested - and gathered then read/reviewed that pertinent data?

    Many, many posts here describe & model code to create delays - and such (more focused & appropriate) delays appear w/in the search items - earlier suggested.

  • Hello Ahmad

    A delay loop takes 3 instructions. So a delay of 10 would be 30 instruction cycles or 30/16MHz worth of delay.

    Regards
    Amit
  • Hi Amit,

    Might you (also) comment upon poster's "use" of many standard "defines" w/in his initial post? One suggests issues (far beyond "delay") await helpers...