Pallav Aggarwal

variable declaration problem

Discussion created by Pallav Aggarwal on Apr 13, 2006
Latest reply on Apr 20, 2006 by TIM LAPSLEY
i have written a code for LCD display but in out fuction if statment is casing error while simulating in real timesimulator of codewarrior it is giving
 
error at location 0080 (fl)
attempt to use invalid or uninitiasized memory
 
i have defined fl as unsigned char (=0 initially) globaly but when i call in out function it is giving the error 
 
//Programm to display AC Voltage & Current/DC Voltage
//AC/DC Display Selection by jumper
//Voltage/Current range selection by jumpers
//onboard Reset/Mon8 connector
//AD0 & AD1 used as analog input
//PTB0-3 LCD Display data
//PTB4 Enable
//PTB5 RS
//PTB6 -7Voltage range selection by jumper.
//PTA4 Current range selection
//PTA5 AC/DC Diplay Selection
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908QY2.h> /* include peripheral declarations */
 
//macro defination for PORTB out
#define setbit(A,B) A|=(1<<B)
#define clrbit(A,B) A&=~(1<<B)
unsigned char fl=0;
void delay()
{
 int del;
 for(del=0;del<234;del++);
}
void del()
{
 int d1,d2;
 for(d2=0;d2<1;d2++)
 {
 for(d1=0;d1<350;d1++);
 }
}
void out(unsigned char lcd_data)
{
 // higher nibble 1st then lower nibble
 
 //initialisation
 DDRB = 0x3F; // 0011 1111  
 PTB=0;//initially PTB out =0
 PTBPUE=0xC0; //11 00 0000
 
 PTB = (lcd_data & 0xF0)>>4;
 
 if(fl == 1)
 setbit(PTB,5); // rs = 1;
 
 setbit(PTB,4); // en = 1;
 setbit(PTB,4); // en = 1;
 setbit(PTB,4); // en = 1;
 clrbit(PTB,4); // en = 0;
 
 PTB = lcd_data & 0x0F;
 
 if(fl == 1) 
 setbit(PTB,5); // rs = 1;
 
 setbit(PTB,4); // en = 1;
 setbit(PTB,4); // en = 1;
 setbit(PTB,4); // en = 1;
 clrbit(PTB,4); // en = 0;
   
 clrbit(PTB,5); //  rs = 0;
 
 fl = 0;
 delay();
}
 

void main(void)
{
//initialization code
 delay();//power up delay
 delay();
 delay();
 delay();
 
 CONFIG1=0x01; //disable COP
 //main function
 
 //initializing LCD
 out(0x30);//commands
 out(0x30);
 out(0x30);
 out(0x20);
 out(0x28);
 out(0x0c);
 out(0x06);
 out(0x02);
 out(0x01);
 
  while(1)
  {
    out( 0x80);
    
    fl=1;
     out('D');
    out('C');
     out(' ');
     out('V');
     out('o');
     out('l');
     out('t');
     out(' ');
     out(' ');
     out(' ');
  }
  
}
 
please help as soon as possible
 
best regards
Pallav

Outcomes