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.

interfacing tiva c series to 16 X 2 LCD

Other Parts Discussed in Thread: TM4C123GH6PM, EK-TM4C123GXL, CCSTUDIO, LM3S1968

I am trying to interface a 16 x 2 LCD to my TIVA C series launchpad TM4C123GH6PM, using the keil tool. I am building this project from the scratch and haven't included any headers or added any file to my project ( except the source code ). My code is given below


// port B is for D0-D7
// PE2 is rs
// PE1 is rw
// PE0 is en
// PB7 is busy

// have to initialise port B and port E
#define ldata (*((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_PORTE_DATA_R (*((volatile unsigned long *)0x400243FC)) // bits 7-0
#define GPIO_PORTE_DIR_R (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_DEN_R (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_AMSEL_R (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R (*((volatile unsigned long *)0x4002452C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))

#define rs (*((volatile unsigned long *)0x40024010))
#define rw (*((volatile unsigned long *)0x40024008))
#define en (*((volatile unsigned long *)0x40024004))
#define busy (*((volatile unsigned long *)0x40005200))

unsigned char string[]={'M','A','X','E','R','I','E','N','C','E'};

void lcd_cmd(unsigned char value);
void lcd_data(unsigned char value);
void lcd_ready(void);
void sendString(void);

void delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<50;j++);
}

void sendString()
{
char i;
for(i=0;i<14;i++)
{
lcd_data(string[i]);
}
}

void lcd_cmd(unsigned char value)
{
lcd_ready();
ldata=value;
rs=0;
rw=0;
en=1;
delay(5);
en=0;
return;
}
void lcd_data(unsigned char value)
{
lcd_ready();
ldata=value;
rs=1;
rw=0;
en=1;
delay(5);
en=0;
return;
}

void lcd_ready()
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
delay(5);
en=1;
}
return;
}

void PortB_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x02; // 1) activate Port B
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
// 2) no need to unlock PB7-0
GPIO_PORTB_AMSEL_R &= ~0xFF; // 3) disable analog functionality on PB7-0
GPIO_PORTB_PCTL_R = 0x00000000; // 4) configure PB7-0 as GPIO
GPIO_PORTB_DIR_R |= 0xFF; // 5) make PB7-0 out
GPIO_PORTB_AFSEL_R &= ~0xFF; // 6) disable alt funct on PB7-0
GPIO_PORTB_DR8R_R |= 0xFF; // enable 8 mA drive on PB7-0
GPIO_PORTB_DEN_R |= 0xFF; // 7) enable digital I/O on PB7-0
}

void PortE_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x10; // 1) activate Port E
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
                                                    
GPIO_PORTE_AMSEL_R &= ~0x07; // 3) disable analog function on PE1-0
GPIO_PORTE_PCTL_R &= ~0x00000FFF;// 4) configure PE1-0 as GPIO
GPIO_PORTE_DIR_R &= 0x07; // 5) make PE1-0 in
GPIO_PORTE_AFSEL_R &= ~0x07; // 6) disable alt funct on PE1-0
GPIO_PORTE_DEN_R |= 0x07; // 7) enable digital I/O on PE1-0
}

int main()
{
//lcd_cmd(0x3C); /* 10x5 dot matrix, 2 line dislay, 8 bit data line*/
lcd_cmd(0x38); // 8 BIT DATA , 2LINE, 5X7 DOT MATRIX
lcd_cmd(0x0E); // DISPLAY ON, CURSOR ON, NO BLINK
lcd_cmd(0x01); //CLEAR DISPLAY
sendString();
}

upon compilation i am getting no errors but during the build operation i get the following error

.\lcd_interface2.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_tm4c123.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
".\lcd_interface2.axf" - 1 Error(s), 0 Warning(s).
Target not created

  • Hello Gourav,

    The headers need to be added in the lcd_interface2 files for the Macro defintion.

    Secondly there is a function called SystemInit in the startup_tm4c123.c file which does not have a definition, hence during link phase it will give an error.

    Couple of suggestions based on the code

    1. Always use an existing project to start a code. It will reduce a lot of the unwanted errors and issues.

    2. Preferably use the API's instead of the Macro's as in the case above. It will help make the code more readable and avoid configuration errors

    Regards

    Amit

  • Gourav Zutshi said:
    #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_PORTE_DATA_R (*((volatile unsigned long *)0x400243FC)) // bits 7-0
    #define GPIO_PORTE_DIR_R (*((volatile unsigned long *)0x40024400))
    #define GPIO_PORTE_AFSEL_R (*((volatile unsigned long *)0x40024420))
    #define GPIO_PORTE_DEN_R (*((volatile unsigned long *)0x4002451C))
    #define GPIO_PORTE_AMSEL_R (*((volatile unsigned long *)0x40024528))
    #define GPIO_PORTE_PCTL_R (*((volatile unsigned long *)0x4002452C))
    #define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))

    You, can find some of those defines at \inc\tm4c123gh6pm.h. So, you just need to include that header file at your main c file.

    Gourav Zutshi said:
    .\lcd_interface2.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_tm4c123.o).
    Not enough information to list image symbols.

    It seems you did something wrong when you created a new project. 

    If you are not that familiar with creating a new project from scratch procedure, I suggest you use a known working example program such as "hello", then just append your code.

    - kel

  • Pardon me, for i am just an undergraduate student and starting everything from the very beginning. Could you help me and tell me which headers and files do i need to add to make the code run.

  • Hello Gourav

    As Kel and myself mentioned, you can use one of the existing projects. These are in the examples/boards/ek-tm4c123gxl folder of the TIVAWare Installation. Also the header files that need to be included in the main code are in the inc and driverlib folder where you would have installed TIVAWare software.

    Since you mentioned that you are an under-grad: You would need to describe the system you have as to what kind of LCD Panel, it's min and max clocking requirements and how you plan to interface it to the TM4C. Once this is done, you should create a programming model of the application code and then being coding.

    Regards

    Amit

  • sir, what if i want to start from the scratch and build my project. what steps should i follow

  • Hello Gourav,

    Then start with the Training Material found at the following link.

    http://processors.wiki.ti.com/index.php/Getting_Started_with_the_TIVA%E2%84%A2_C_Series_TM4C123G_LaunchPad#Workshop_Material

    Regards,

    Amit

  • in keil and not in ccstudio.

  • Hi,

    For just Keil and just your style (no driverlib) this site has many examples:

    http://users.ece.utexas.edu/~valvano/arm/

    Petrei

  • Thanks a  lot for the link. I managed to find a folder that contained the code and necessary files that were required to interface the LCD. But the code and files are given for LM3S1968. I tried to change the registers and get the job done on TIVA C series kit. The LCD does not show the required text. If anyone has done the LCD experiment on keil kindly send the necessary files and code.  

  • Hi,

    At this stage I don't think you need other files - all is contained there. Check to see if there are some files for LM4F (same thing as TM4C) - compare the pins configurations, understand how it works, check your again. 

    Depending how you managed the contrast adjustment (pin 3 if I remember well) you may have there a potentiometer - try to adjust, move to various positions up and down and see the characters, could be just hidden by a bad level.

    Petrei

  • umm i haven't connected the potentiometer to pin 3 of the lcd. Could that be the reason for not getting the output?

  • I've grounded the contrast pin for maximum contrast, still no results 

  • Hi,

    Then .zip the relevant files to have a look at them.

    Be precise when saying "no output" - nothing shown on display? Did you checked with an oscilloscope the pins working? Do they have the correct shape? What display do you use? Because many are for 5V opertion while the micro delivers only 3V signals.

    Petrei

  • Might these 4 items confound you/your helpers?

    a) more than 40 lines of direct register code greatly complicates - do you really expect people to make that kind of time/effort commitment?

    b) have you fully/properly complied with HD44780/clone data sheet specifications especially where initialization delays -inter-character delays - and CLS delays (i.e. 0x01) are concerned?

    c) does your, "back to back" code sequence impacting RS, RW & E provide for the (required) set-up time between RS/RW and E?

    d) might your "read of the busy bit" hold all follow-on code hostage?  Your posts provide no mention whatsoever of your code's "sequencing" among the various functions.

    You report the "find" of new/example code - yet only the original code has reached this space.  Are not all your responders, "shooting fish" w/in a 2nd barrel.  (and both 1st & 2nd barrels filled w/very murky water...)

  • By no output i mean a blank lcd, even after the running the code, the lcd i use is JHD162A and i use 5 volts supply for it . I've taken the 5 volts from the Vbus of the Tiva C series controller and powered the board using the usb connection to the laptop. I'll attach the files i've used.

    LCD_exp.zip
  • Hi,

    In file lcd.c you declared to use PG0..2 and PF0...7 to interface with the display and still your LCDInit function uses original PB and PE ports. Is that OK with you?

    Also, take into account the port PF pin 0 is default as NMI, so you need to unlock it before using /configuring as output.

    Petrei

  • the code that was given was for LM3S1968, so for using it for TM4C123GH6PM i changed the ports and used port B for data and PE2-PE0 for the control signals and didn't change the control signals. i didn't change the comments though. So the code uses PB for data and PE2-0 for rs,rw and en.

  • Hi,

    And are you sure these constants are not further called by the code? Try using the debugger to debug step by step until you discover what is wrong.

    Petrei

  • i tried running the original code (that i wrote in the beginning of the question) and i also tried the other code for lm3s1968. In both the cases i now get a completely filled display on the lcd (i.e. 16 boxes in one line).

  • Hi,

    At least can you explain what was the cause of several failures? And mark this question as answered.

    Petrei

  • i know all this has been really frustrating , but i still haven't reached the result. the reason i got black boxes was because the lcd pins were loosely connected . So that means something is wrong with the code now.

  • So maybe there is something wrong with hardware - at this stage only debugging step by step would reveal where is the problem. Set a breakpoint after a line like LCDCMD=5 and check if the pins RS, RW, E are in the prescribed status. Repeat for the rest of the data pins.

    Petrei

  • thanks a lot for your help i single stepped the code and realized that port E wasn't reading the values at all, so i made some changes, then i adjusted the delays and finally got the required output. 

  • But ... How to resolve this issue while building the project from the scratch without using any created project.