Im using KEIL 4.74.0.0 for programming TM$C123GH6PM.
when I debug the below program im getting hard fault exception handler
/// PROGRAM FOR LCD DISPLAY //////
#include"tm4c123gh6pm.h"
#define rs 0
#define rw 1
#define en 2
void delay(unsigned int k)
{
int i,j;
for(i=0;i<k;++i)
for(j=0;j<1000;++j);
}
void cmd(unsigned char y)
{
GPIOD->DATA=0<<rs;
//GPIOD->DATA=0<<rw;
//GPIOB->DATA=y;
//GPIOD->DATA=1<<en;
// delay(30);
//GPIOD->DATA=0<<en;
}
void data(unsigned char y)
{
GPIOD->DATA=1<<rs;
GPIOD->DATA=0<<rw;
GPIOB->DATA=y;
GPIOD->DATA=1<<en;
//delay(1000);
GPIOD->DATA=0<<en;
}
void lcd_init()
{
cmd(0x38);
//cmd(0x0e);
// cmd(0x80);
}
int main()
{
int i;
SystemInit();
/* SYSCTL->RCC=1<<11; // set Bypass
SYSCTL->RCC|=(0<<22); // clear USESYSDIV
SYSCTL->RCC|=(0<<13)|(0<<5)|(0<<4)|(0x15<<6); //PWRDN clear, MAIN OSC select,XTAL 16 MHz
SYSCTL->RCC|=(0x3<<23)|(1<<22); //SYSDIV 3, set USESYSDIV
while(((SYSCTL->RIS&0x00000040)==0)); // wait 4 PLL to LOCK
SYSCTL->RIS=1<<6; // clear PLLRIS interrupt
SYSCTL->RCC|=0<<11;
for(i=0;i<1000;++i);
*/
SYSCTL->RCGCGPIO=1<<1;
GPIOB->DIR=0xff;
GPIOB->AFSEL=0x00;
GPIOB->DEN=0xFF;
SYSCTL->RCGCGPIO=1<<3;
GPIOD->DIR=0xff;
GPIOD->AFSEL=0x00;
GPIOD->DEN=0xff;
SYSCTL->RCGCGPIO=1<<5;
GPIOF->DIR=0xFF; //output
GPIOF->AFSEL=0x00; // as GPIO
GPIOF->DEN=0xff; // as DIGITAL pins
GPIOF->DATA=0<<1;
lcd_init();
GPIOF->DATA=1<<1;
while(1)
{
cmd(0x80);
data('V');
}
}
when lcd_init(); function is called it jumps to hard fault exception handler.
Please help me to solve this problem.