AnsweredAssumed Answered

ILLEGAL_BP when running my program (mc9s12dp512)

Question asked by ibtisbr on Apr 10, 2017
Latest reply on Apr 11, 2017 by ZhangJennie

Hello , 

 

I'm working toward a project and i want to display some data into a 16x2 LCD using mc9s12dp512 but when runing the program below i get illegal_bp as shown in the attached picture , any idea how i can solve it ? 

#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "c:\Program Files (x86)\Freescale\CWS12v5.2\lib\hc12c\include\mc9s12dp512.h"
#define data_port PORTA;


#define rs PORTA_BIT0;
#define rw PORTB_BIT1 ;
#define en PORTB_BIT2 ; // pulse count





void delay_ms(unsigned int msec) {
int i ;
{
while (msec != 0)
{
for (i=5; i >0;i--){};
break;
}

}

}
void lcd_cmd(unsigned char dat)
{

dat =PORTA & 0xFF;
PORTB=PORTB & 0xF1 ;// CLEARS rs=0
PORTB=PORTB & 0xF2;//rw 0;
PORTB=PORTB | 0xFB;//en 1 sets the bit 2 of PORTB to 1 ;
delay_ms(1);
PORTB=PORTB & 0xF4;

}

void lcd_data(unsigned char dat) // Function to send data to LCD
{

dat = PORTA & 0xFF;
PORTB=PORTB | 0xFE; // Rs=1
PORTB=PORTB & 0xF2; //RW=0
PORTB=PORTB | 0xFB;//EN=1
delay_ms(1);
PORTB=PORTB & 0xF4; //EN=

}

void lcd_string( char *str) // Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
delay_ms(1);
}
}
main (){
DDRB =0xFF;
DDRA= 0xFF;


lcd_cmd(0x38);
lcd_cmd(0x0c);
delay_ms(2);
lcd_cmd(0x01);
delay_ms(2);
lcd_cmd(0x80);
delay_ms(2);

lcd_string("Range finder");
return 0;

}

Attachments

Outcomes