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.

solved LCD interface with tm4c123gh6pm

Other Parts Discussed in Thread: TM4C123GH6PM

#include <tm4c123gh6pm.h>


unsigned int i,j,del;

void delay(unsigned int f)

{
f=(SystemCoreClock*f)/1000;
for(i=0;i<f;i++);
}
void cmd(unsigned int a)
{GPIOE->DATA=(0<<1|0<<2|0<<3);
GPIOE->DATA|=0<<1;
GPIOE->DATA|=0<<2;
GPIOB->DATA=a;
GPIOE->DATA|=1<<3;
delay(1);
GPIOE->DATA|=0<<3;
}

void data(unsigned char b)
{
GPIOE->DATA=(0<<1|0<<2|0<<3);
GPIOE->DATA|=1<<1;
GPIOE->DATA|=0<<2;
GPIOB->DATA=b;
GPIOE->DATA|=1<<3;
delay(1);
GPIOE->DATA|=0<<3;
}
void lcd_init()
{
cmd(0x38);
cmd(0x0E);
cmd(0x01);

}

int main()
{ unsigned char l[4]="ASHA";
SYSCTL->RCC=(1<<6|1<<8|1<<10|1<<22|1<<24);//sytem clk set,pll enabled,xtal crystal 16MHZ,sysdiv_3 66.67MHZ
SYSCTL->RCGCGPIO=(1<<1|1<<4);//configure port E and port B
GPIOE->DIR=0XFF;//set port E as o/p
GPIOE->AFSEL=0X00;//alternate fun as GPIO
GPIOE->DEN=0XFF;//enable digital pins
GPIOE->AMSEL=0x00;
GPIOB->DIR=0XFF;//set port B as o/p
GPIOB->AFSEL=0X00;//alternate fun as GPIO
GPIOB->DEN=0XFF;//enable digital pins
GPIOB->AMSEL=0x00;
lcd_init();

while(1)
{ cmd(0x80);
for(j=0;j<4;j++)
{
data(l[j]);delay(10);
}
}

}

i got the output using direct register access method..

  • Asha Antonyraj said:

    i got the output using direct register access method..  

    Good that - yet I'd urge (others) to pay (some) attention to the "variety" of delay times which such character based Lcds demand.

    I'd hazard the guess that poster's code could only work w/the MCU cranked far down - and/or (most likely) "single-stepped" - as he's severely violated the Lcd's Control spec!

    Poster's code here continues to violate:

    a) HD44780's standard initialization sequence (although he's removed the needless duplication of "home" which I past noted)

    b) HD44780's rather strict initialization timing is completely absent

    c) Lcd's RS & E appear to be toggled together - spec's timing chart reveals this as improper

    d) the extra delay required by 0x01 has not been accommodated

    e) Command & Data functions employ different data types w/out justification

    Poster earlier had a near duplicate posting - it was suggested that he find & comply w/Lcd Control spec - this (latest) DRM code does not signal compliance.

    Might it be that the extra time & effort demanded (always) by direct register - reduced the time available for a proper review of the Lcd spec?

    As one (past) highly successful in the Lcd field I do not recommend poster's code - as presented here - as, "Ready for Prime Time!"

  • Hello Asha,

    I see a lot of value in cb1's post. Your method while is working is guaranteed that when all pieces of the system are put in place and the code revisited in 4 weeks, will be a pain to understand. Critical functions like setting of the PLL may be more worrisome.

    Regards
    Amit
  • Amit Ashara said:
    I see a lot of value...

    Thank you for that kindness, Amit - as always, appreciated.

    Perhaps as a reminder to others (I don't believe o.p. is yet "reachable") the use of Direct Register Macros demands painstaking effort - and great time/exacting attention to detail - to get right.   And - when completed - you stand ALONE!  

    A far superior alternative - often suggested by Amit - is use of this vendor's API - which is detailed, tried/true, and wonderfully expansive.   Rejecting this API in favor of a, "One Off, DRM effort" demanding greatly detailed, "Register Digs" is neither cost, time, nor effort efficient.   And we note - the DRM code produced - unless expansively commented - will most surely be "cryptic" w/in a few weeks of time passage.   And NEVER, "tried/true, and wonderfully expansive" - as is the API.

    In dealing with any external device - a fair/proper read/review of the device's specs/data is normal/customary.   Poster here appears not to have made that effort - that's a bad habit - which most surely will not lead to success!