please explain me the error in the below C code for PIC16F877A compiled in MPLAB

Status
Not open for further replies.

rangerskm

Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,663
Code:
#include<pic.h>


#define enter 0x0d
#define ctrlz 0x1a

#define sendb RC0

#define rs RB0
#define rw RB1
#define en RB2
#define lcdport PORTB

int convert[16]='0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F';
int lcd[16]=0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78;
unsigned int x,temp,adc_value,countdata,digit1,digit2,digit3,digit4,digit5,air,temperature,humidity,sound,water,time;
unsigned int vd,lat[11],lon[12];

void initialisemodem();
void deleteallmsg();
void sendtestmsg();
void send_data();
void snumber();			//stored number
void readmessage();

void read_gps();

void hextobcd();
void acd_config();
void adc_data_accure();
void acd_read(int);

void delay(int);

void initialise_lcd();
void command(int);
void display(int);
void dout_lcd(int);

void main()
{

TRISA=0xFF;  // PORTA is input
TRISC=0xFF;  // PORTC is input
TRISB=0x00;
TRISD=0x00;
PORTB=0X00;
PORTD=0x00;

humidity=0;
temperature=0;
sound=0;
water=0;

acd_config();

TXSTA=0b00100100;  // Configure serialport
RCSTA=0b10010000;  // Configure serialport
SPBRG=25;  // Configure serialport

delay(50);
initialise_lcd();
delay(50);

command(0x01);
command(0x80);
display('A');
display('N');
display(' ');
display('I');
display('T');
display('I');
display('N');
display('E');
display('R');
display('A');
display('N');
display('T');
display(' ');
display('G');
display('S');
display('M');
display('-');
display('G');
display('P');
display('S');

command(0xc0);
display('A');
display('N');
display('D');
display(' ');
display('S');
display('E');
display('N');
display('S');
display('O');
display('R');
display('S');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

command(0x94);
display('I');
display('N');
display('T');
display('E');
display('G');
display('R');
display('A');
display('T');
display('I');
display('O');
display('N');
display(' ');
display('F');
display('O');
display('R');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

command(0xd4);
display('E');
display('N');
display('V');
display('I');
display('O');
display('R');
display('N');
display('A');
display('M');
display('E');
display('N');
display('T');
display('A');
display('L');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

delay(5000);

command(0xd4);
display('E');
display('F');
display('F');
display('L');
display('U');
display('E');
display('N');
display('C');
display('E');
display(' ');
display('S');
display('C');
display('R');
display('E');
display('E');
display('N');
display('I');
display('N');
display('G');
display(' ');

delay(5000);

initialisemodem();
delay(1000);

command(0x01);
command(0x80);
display('D');
display('E');
display('L');

deleteallmsg();
delay(1000);

command(0x01);
command(0x80);
display('T');
display('S');
display('T');

sendtestmsg();
delay(1000);

command(0x01);

time=0;

loop:

command(0x80);
display('T');
display(':');
acd_read(0);
temperature=adc_value;
temp=temperature;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display('.');
display(convert[digit5]);
display('C');
display(' ');
display(' ');
display(' ');

display('H');
display(':');
acd_read(1);
humidity=adc_value;
temp=(humidity/10);
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('R');
display('H');
display(' ');
display(' ');


command(0xc0);
display('W');
display(':');
acd_read(2);
water=adc_value/5;
temp=water;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('T');
display('D');
display('S');
display(' ');
display(' ');


display('S');
display(':');
acd_read(4);
sound=adc_value;
temp=sound/10;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('d');
display('B');
display(' ');
display(' ');


command(0x94);
display('A');
display(':');
acd_read(5);
air=adc_value;
temp=air;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);

delay(10000);

read_gps();

if(vd=='A')
{
command(0x01);
command(0x80);
display('L');
display('A');
display(':');
display(lat[0]);
display(lat[1]);
display(lat[2]);
display(lat[3]);
display(lat[4]);
display(lat[5]);
display(lat[6]);
display(lat[7]);
display(lat[8]);
display(lat[9]);
display(lat[10]);

command(0xc0);
display('L');
display('O');
display(':');
display(lon[0]);
display(lon[1]);
display(lon[2]);
display(lon[3]);
display(lon[4]);
display(lon[5]);
display(lon[6]);
display(lon[7]);
display(lon[8]);
display(lon[9]);
display(lon[10]);
display(lon[11]);

delay(5000);

}

else
{
command(0x01);
command(0x80);
display('I');
display('N');
display('V');
display('A');
display('L');
display('I');
display('D');
display(' ');
display('D');
display('A');
display('T');
display('A');
display(' ');
display(' ');
display(' ');
display(' ');

delay(1000);
}


if(sendb==0)
{
time=time+1;
if(time==5)
{
command(0x01);
command(0x80);
display('S');
display('E');
display('N');
display('D');
display('I');
display('N');
display('G');
display(' ');

delay(500);

time=0;
send_data();

}
}
goto loop;


}

void hextobcd()
{
countdata=temp;
countdata=(countdata/10000);
digit1=countdata;
countdata=(countdata*10000);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/1000);
digit2=countdata;
countdata=(countdata*1000);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/100);
digit3=countdata;
countdata=(countdata*100);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/10);
digit4=countdata;
countdata=(countdata*10);
temp=(temp-countdata);

digit5=temp;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void initialisemodem()
{
TXREG='A';			//change modem to text mode
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='F';
delay(5);
TXREG='=';
delay(5);
TXREG='1';
delay(5);
TXREG=enter;
delay(5);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void deleteallmsg()
{
TXREG='A';			//DELETE ALL MESSAGES
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='D';
delay(5);
TXREG='A';
delay(5);
TXREG='=';
delay(5);
TXREG=0x22;
delay(5);
TXREG='D';
delay(5);
TXREG='E';
delay(5);
TXREG='L';
delay(5);
TXREG=' ';
delay(5);
TXREG='A';
delay(5);
TXREG='L';
delay(5);
TXREG='L';
delay(5);
TXREG=0x22;
delay(5);

TXREG=enter;
delay(5);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
			
void sendtestmsg()
{
snumber();

TXREG='T';
delay(5);
TXREG='E';
delay(5);
TXREG='S';
delay(5);
TXREG='T';
delay(5);
TXREG=ctrlz;
delay(5);
}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void send_data()
{
snumber();

TXREG='D';
delay(5);
TXREG='A';
delay(5);
TXREG='T';
delay(5);
TXREG='A';
delay(5);
TXREG=':';
delay(5);

TXREG='L';
delay(5);
TXREG='A';
delay(5);
TXREG='T';
TXREG='=';
delay(5);

TXREG=(lat[0]);
delay(5);
TXREG=(lat[1]);
delay(5);
TXREG=(lat[2]);
delay(5);
TXREG=(lat[3]);
delay(5);
TXREG=(lat[4]);
delay(5);
TXREG=(lat[5]);
delay(5);
TXREG=(lat[6]);
delay(5);
TXREG=(lat[7]);
delay(5);
TXREG=(lat[8]);
delay(5);
TXREG=(lat[9]);
delay(5);
TXREG=(lat[10]);
delay(5);
TXREG=',';
delay(5);

TXREG='L';
delay(5);
TXREG='O';
delay(5);
TXREG='N';
delay(5);
TXREG='=';
delay(5);

TXREG=(lon[0]);
delay(5);
TXREG=(lon[1]);
delay(5);
TXREG=(lon[2]);
delay(5);
TXREG=(lon[3]);
delay(5);
TXREG=(lon[4]);
delay(5);
TXREG=(lon[5]);
delay(5);
TXREG=(lon[6]);
delay(5);
TXREG=(lon[7]);
delay(5);
TXREG=(lon[8]);
delay(5);
TXREG=(lon[9]);
delay(5);
TXREG=(lon[10]);
delay(5);
TXREG=(lon[11]);
delay(5);
TXREG=',';
delay(5);


TXREG='T';
delay(5);
TXREG='=';
delay(5);
temp=temperature;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG='.';
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='C';
delay(5);
TXREG=',';
delay(5);

TXREG='H';
delay(5);
TXREG='=';
delay(5);
temp=(humidity/10);
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='R';
delay(5);
TXREG='H';
delay(5);
TXREG=',';
delay(5);


TXREG='W';
delay(5);
TXREG='=';
delay(5);
temp=water;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='T';
delay(5);
TXREG='D';
delay(5);
TXREG='S';
delay(5);
TXREG=',';
delay(5);


TXREG='S';
delay(5);
TXREG='=';
delay(5);
temp=sound/10;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='d';
delay(5);
TXREG='B';
delay(5);
TXREG=',';
delay(5);


TXREG='A';
delay(5);
TXREG='=';
delay(5);
temp=air;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);

TXREG=ctrlz;
delay(5);
}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
		

void snumber()
{
TXREG='A';			
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='S';
delay(5);
TXREG='=';
delay(5);

TXREG=0x22;
delay(5);
TXREG='9';
delay(5);
TXREG='7';
delay(5);
TXREG='8';
delay(5);
TXREG='7';
delay(5);
TXREG='0';
delay(5);
TXREG='7';
delay(5);
TXREG='1';
delay(5);
TXREG='7';
delay(5);
TXREG='9';
delay(5);
TXREG='1';
delay(5);
TXREG=0x22;
delay(5);

TXREG=enter;
delay(5);

}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void read_gps()
{
if(OERR==1)
{
SREN=0;
temp=RCREG;
temp=RCREG;
CREN=0;
CREN=1;
SREN=1;
}

loop:

while(RCIF==0)
{
}
temp=RCREG;
if(temp!='$')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='G')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='P')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='R')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='M')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='C')
{
goto loop;
}

for(x=0;x<12;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<1;x++)			// valid transmission data
{
while(RCIF==0)
{
}
temp=RCREG;
vd=temp;
}

for(x=0;x<1;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<11;x++)			//collect latitude
{
while(RCIF==0)
{
}
temp=RCREG;
lat[x]=temp;
}

for(x=0;x<1;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<12;x++)			//collect longitude
{
while(RCIF==0)
{
}
temp=RCREG;
lon[x]=temp;
}

}


//////////////////////////////////////////////////////////////////////////////////////////
void acd_config()
{
  ADCON1=0b10000001;
  ADCON0=0b01000001;
  delay(1);
}

//////////////////////////////////////////////////////////////////////////////////////////
void acd_read(int channel)
{

if (channel==0)
{
ADCON0=0b01000001;
adc_data_accure();
} 
else if (channel==1)
{
ADCON0=0b01001001;
adc_data_accure();
} 
else if (channel==2)
{
ADCON0=0b01010001;
adc_data_accure();
} 
else if (channel==3)
{
ADCON0=0b01011001;
adc_data_accure();
} 
else if (channel==4)
{
ADCON0=0b01100001;
adc_data_accure();
} 
else if (channel==5)
{
ADCON0=0b01101001;
adc_data_accure();
} 
else if (channel==6)
{
ADCON0=0b01110001;
adc_data_accure();
} 
else
{
}
}
  
//////////////////////////////////////////////////////////////////////////////////////////
void adc_data_accure()
{
delay(1);
ADCON0=ADCON0|0b00000100;
delay(1);
adc_value=ADRESL; 		//collect ADRESL value 
adc_value+=(ADRESH<<8); //collect ADRESH value and add with ADRESL value 
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void delay(int time)
{
int i,j;
for(j=1;j<=time;j++)
{
for(i=0;i<=64;i++)
{
}
}
}

//////////////////////////////////////////////////////////////////////////////////////////
void initialise_lcd()
{
command(0x2c);           //4bits/char,2 rows,5x10 dots/char 
command(0x0c);          //screen on,cursor off and no blink     			
command(0x06);           //shift cursor right
command(0x01);           //clear memory and home cursor    
command(0x80);           //move cursor to space(0) 0,line 1(8)
}			

//////////////////////////////////////////////////////////////////////////////////////////			
void command(int lcddata)
{
delay(5);
rs=0;
rw=0;
dout_lcd(lcddata);
}
//////////////////////////////////////////////////////////////////////////////////////////
void display(int lcddata)
{
delay(5);
rs=1;
rw=0;
dout_lcd(lcddata);
}

//////////////////////////////////////////////////////////////////////////////////////////
void dout_lcd(int lcddata)
{
temp=lcddata;
temp=temp>>4;
temp=temp&0x0f;
lcdport=lcdport&0x07;
lcdport=lcdport|lcd[temp];

en=1;
en=0;

temp=lcddata;
temp=temp&0x0f;
lcdport=lcdport&0x07;
lcdport=lcdport|lcd[temp];

en=1;
en=0;

}

compiler used HI TECH C LITE,please explain the error and please correct me in this.
error message

Code:
HI-TECH C PRO for the PIC10/12/16 MCU family (Lite)  V9.65PL1
Copyright (C) 1984-2009 HI-TECH SOFTWARE
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0x80A in 2 bytes at 0x1010 (renew 3.obj 229/0x44)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0x80B in 2 bytes at 0x1012 (renew 3.obj 229/0x46)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0x991 in 2 bytes at 0x1014 (renew 3.obj 231/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xA3C in 2 bytes at 0x1320 (renew 3.obj 252/0x3A)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xA41 in 2 bytes at 0x147E (renew 3.obj 265/0x2C)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xA42 in 2 bytes at 0x1480 (renew 3.obj 265/0x2E)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xABF in 2 bytes at 0x1482 (renew 3.obj 265/0x30)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xA50 in 2 bytes at 0x149C (renew 3.obj 265/0x4A)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xA51 in 2 bytes at 0x149E (renew 3.obj 265/0x4C)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 380. fixup overflow storing 0xABF in 2 bytes at 0x14A0 (renew 3.obj 267/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0x80A in 2 bytes at 0x1F80 (renew 3.rlf 5373/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0x80B in 2 bytes at 0x1F80 (renew 3.rlf 5377/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0x991 in 2 bytes at 0x1F80 (renew 3.rlf 5383/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xA3C in 2 bytes at 0x1F80 (renew 3.rlf 6457/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xA41 in 2 bytes at 0x1F80 (renew 3.rlf 6927/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xA42 in 2 bytes at 0x1F80 (renew 3.rlf 6931/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xABF in 2 bytes at 0x1F80 (renew 3.rlf 6937/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xA50 in 2 bytes at 0x1F80 (renew 3.rlf 6967/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xA51 in 2 bytes at 0x1F80 (renew 3.rlf 6971/0x0)
Error   [1268] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\old renew\renew 3\renew 3.c; 14. fixup overflow storing 0xABF in 2 bytes at 0x1F
 
Last edited by a moderator:

There is no error in your file It compiles as it was and there is only a warning

Code C - [expand]
1
2
3
4
Warning at file ../main.c line 16 column : (1090) variable "_digit1" is not used, I think your Ram variables got over flow in Lite mode compilation put [B]const[/B] keyword
 
const int Lcd[]
const int convert[]


they will work fine......

- - - Updated - - -

And I atttached the compiled hex file in hitech pro mode...
 

Attachments

  • pic 16f877a.7z
    56 KB · Views: 59
Last edited:

hi brother
i got same error when used const
const int convert[16]='0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F';
const int lcd[16]=0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78;

whats the reason ??
 

how can i get hi tech c pro??
 

you can activate free 45 day trial of "HI-TECH C Compiler for PIC10/12/16 MCUs" by downloading and installing it..

**broken link removed**
 

please explain these piece of code which is used to send numeric datas through usart
Code:
#define SEND_SER(data) TXREG=data;while(!TRMT);
//


void SEND_time(unsigned int val)
{
	unsigned int a[10] = {0},cnt=1;
	unsigned int temp = val;
	if(!val)
	{
		cnt++;
	}
	while(val)
	{
		a[cnt++] = val%10;
		val = val/10;
	}
	if(temp>10)
	{
		cnt--;	
	}	
	while(cnt)
	{
		SEND_SER(a[cnt--]+'0');
	}	
}
 

hello,

To reduce amount of used ram
instead of integer you can use unsigned char table , because size of data is one byte.

unsigned char convert[16]='0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F';
unsigned char lcd[16]=0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78;


and you get error because you want to put a int inside a byte
TXREG=(lat[0]);
TXREG is a register (1 byte)
lat[0] is 4 bytes

or use cast
TXREG=(unsigned char) lat[0];
but i think it is not what do you want ..
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…