LCD interfacing with stellaris tivaC launchpad TM4C123

1

I wrote a code for LCD interfacing with the tivaC launch pad but when I try to run it nothing appears to be happening i posted the code I have written also i have ensured the hardware connections can the delay function has an impact on not making the LCD work. Is there any logical error in the code that doesn't make the LCD performs it job.

#include "tm4c123gh6pm.h"
#define LCD_RS (*((volatile unsigned long *)0x40004200))    //PA.7 for 
  register select pin
#define LCD_EN  (*((volatile unsigned long *)0x40004100))   //PA.6 for enable 
 pin
#define LCD_RW  (*((volatile unsigned long *)0x40004080))   //PA.5 for rw pin

/*function protoypes */
void LCD_INIT(void);
void LCD_CMD(unsigned long cmd);
void LCD_WRITE (char data);
void Delay(void);

/*this function must be writen as keil 
allows running of a function before the main*/
void SystemInit() {
};

int main (void) {
    LCD_INIT();
    while(1) {
        LCD_CMD(0X38);  //8-bit bus mode, 2 line display mode, 5x8 dots display mode
        Delay();
        LCD_CMD(0X01);  //clear display
        Delay();
        LCD_CMD(0X10);  //cursor display shift
        Delay();
        LCD_CMD(0X0C);  //diplay is on
        Delay();
        LCD_WRITE('A'); //send character A on the LCD 
        Delay();
    }
}

/*this function will initate the LCD it initializes 
the portA5-6-7 as the control pins  for the LCD and portB0-7 
as the data pins*/
void LCD_INIT(void) {
    volatile unsigned long delay;
    SYSCTL_RCGC2_R |= 0X00000002;   // allow the clock for portB
    delay = SYSCTL_RCGC2_R;     // short delay for clock
    GPIO_PORTB_AFSEL_R &= ~0xff;    //disable alternative functions for portB
    GPIO_PORTB_AMSEL_R &= ~0Xff;    //disable analogue function
    GPIO_PORTB_PCTL_R &= ~0XFF;     //regular digital pins
    GPIO_PORTB_DIR_R  |= 0XFF;      //set the direction of PB0-7 as     output
    GPIO_PORTB_DEN_R  |= 0XFF;      //enable digital portB

    SYSCTL_RCGC2_R |= 0X00000001;   // allow the clock for PA5,6,7
    delay = SYSCTL_RCGC2_R;     // short delay for clock
    GPIO_PORTA_AFSEL_R &= ~0xE0;    //disable alternative functions for PA5,6,7
    GPIO_PORTA_AMSEL_R &= ~0XE0;    //disable analogue function for PA5,6,7
    GPIO_PORTA_PCTL_R &= ~0XE0;     //regular digital pins
    GPIO_PORTA_DIR_R |= 0XE0;       //set the direction of PA5,6,7 as output
    GPIO_PORTA_DEN_R |= 0XE0;       //enable digital PA5,6,7
}

//this function passes the command to the LCD
void LCD_CMD(unsigned long cmd) {
    GPIO_PORTB_DATA_R = cmd;    //set PB7-0 as the passed command to the function
    LCD_RS = 0x00;  //set PA7 register select pin to low
    LCD_RW = 0x00;  //set PA5 r/w pin to low
    LCD_EN = 0x40;  //set enable pin to high
    Delay();        //short delay 
    LCD_EN = 0x00;  //set enable pin to low 
}

//this function passes the data to the LCD
void LCD_WRITE (char data) {
    GPIO_PORTB_DATA_R = data;   //write the data to PB7-0
    LCD_RS = 0x80;  //set PA7 to high
    LCD_RW = 0x00;  //set pA5 to low
    LCD_EN = 0x40;  //set the enable pin high
    Delay();        //short delay
    LCD_EN = 0x00;  //set the enable pin to low
}

//short delay function
void Delay(void) {
    unsigned long  time;
    time = 12000; 
    while(time){
        time--;
    }
}
c
microcontroller
cortex-m
lcd
stellaris
asked on Stack Overflow Jul 1, 2018 by ayman magdy • edited Jul 2, 2018 by cooperised

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0