Maker Pro
Maker Pro

Code causes error report from PIC CCS compiler

shatha

Dec 20, 2013
2
Joined
Dec 20, 2013
Messages
2
Hello, I need to help
I need to write code for interfacing gps tracker to p16f877a usin ccs c compiler and i need to proteus file, thank you very much.:)
this code give an erorr, can you test it and tell me what is the problem? :) :)


#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NO DEBUG,NOCPD
#device *=16 // This enables use of all RAM.
#use delay (clock=20000000)
#use fast_io(b)
#define use_portb_lcd TRUE
#include<lcd.c>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7, parity=N, bits=8, ERRORS)
#define BUFFER_SIZE 96

BYTE buffer[BUFFER_SIZE]; // implemented as a circular buffer

int comma = 0;
int dataLen;
int start, end, speedLen=0;
int i;
char speed[10];
char c;

short ReadSerial = 0;
short startok = 0;
int8 index,x;

double parseData() // this function parses the $GPVTG data strings to find the speed information
{
dataLen = strlen(buffer);
for (i=0; i<dataLen; i++)
{
if (buffer == ',')
comma++;
if (comma == 7)
{
i++;
start = i;
while (buffer != ',')
{
speedLen++;
i++;
}
end = i-1;
break;
}
}

for (i=start; i<=end; i++)
{
speed[i-start] = buffer;
}
speed = '\0';
return atof(speed);
}


#int_rda
void gps_isr()
{/// note this routine needs to as short as possible since it is called
/// for each char received from GPS

c=getc() ;

putc(c);
if (c=='$')
{
index = 0;
startok = 1;
}
buffer[index] = c;
index++;
if (index>BUFFER_SIZE)
{
index = 0;
}
if ((index>62) && (startok==1) && (buffer[3]=='V') && (buffer[4]=='T') && (buffer[5]=='G'))
{
startok=0;
disable_interrupts(int_rda);
readserial = 1;
}
}

#separate
void reset_serial()
{
ReadSerial = 0;
index = 0;
for(x=0;x<BUFFER_SIZE;x++) buffer[x]=' '; // reset input buffer
enable_interrupts(int_rda);
}


int main(){

setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED, 0, 1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);

enable_interrupts(GLOBAL);

reset_serial();

set_tris_b(0x00); // set the b port to the output



while(1)
{

if ( readserial == 1 )

{

lcd_init(); // initialize the lcd
lcd_send_byte(0,0x0d);
lcd_gotoxy(1,2);
printf(lcd_putc,"\f SPEED = %f",parseData());
delay_ms(1000);

reset_serial();

}

}
}
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
What is the error and what line is it on?

The error message from the compiler should give you a description of the type of error, and its location.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,722
Joined
Nov 17, 2011
Messages
13,722
Telling us what the error message is and where it occurs is absolutely necessary.

Apart from that, I see a possible runtime problem here:

Code:
for (i=0; i<dataLen; i++)
{
if (buffer[i] == ',')
comma++;
if (comma == 7)
{
i++;
start = i;
while (buffer[i] != ',') /*<- there is a risk that i becomes > dataLen if by chance the memory at that location contains "," */
/* possibly from a previous buffer content. */
/* The check ( i<dataLen) that is in the for-statement is not active here */
{
speedLen++;
i++;
}
end = i-1;
break;
}

But I doubt that this is the error your compiler detected.
 

shatha

Dec 20, 2013
2
Joined
Dec 20, 2013
Messages
2
Telling us what the error message is and where it occurs is absolutely necessary.

Apart from that, I see a possible runtime problem here:

Code:
for (i=0; i<dataLen; i++)
{
if (buffer[i] == ',')
comma++;
if (comma == 7)
{
i++;
start = i;
while (buffer[i] != ',') /*<- there is a risk that i becomes > dataLen if by chance the memory at that location contains "," */
/* possibly from a previous buffer content. */
/* The check ( i<dataLen) that is in the for-statement is not active here */
{
speedLen++;
i++;
}
end = i-1;
break;
}

Thank for your comment but, what is the true to became good.
can you help me,please.
the erorr shows below.
 

Attachments

  • Capture.PNG
    Capture.PNG
    51.1 KB · Views: 209
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The compiler is telling you that it doesn't know what delay_ms is.

Your options are:

1) find the correct name for this routine.
2) find (and include) the correct library containing "delay_ms"
3) write your own delay_ms
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,722
Joined
Nov 17, 2011
Messages
13,722
This line
Code:
while (buffer[i] != ',')
should be amended to
Code:
while (buffer[i] != ',') && (i<dataLen))

This is only one obvious code snippet I found more or less by chance. You should check the full code for other problems.
 

anroop

Dec 11, 2013
65
Joined
Dec 11, 2013
Messages
65
could u send me the program's flow chart so that I can try something with that...
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Did you fix the delay_ms() problem that was causing the compiler to report an error as shown in post #5?

Does your code compile properly now?

What is the symptom of the problem? In other words, what does the code not do that it should do?
 
Top