Connect with us

Code causes error report from PIC CCS compiler

Discussion in 'Microcontrollers, Programming and IoT' started by shatha, Dec 20, 2013.

Scroll to continue with content
  1. shatha

    shatha

    2
    0
    Dec 20, 2013
    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();

    }

    }
    }
     
  2. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    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.
     
  3. Harald Kapp

    Harald Kapp Moderator Moderator

    10,069
    2,150
    Nov 17, 2011
    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.
     
  4. shatha

    shatha

    2
    0
    Dec 20, 2013
     

    Attached Files:

    Last edited: Dec 21, 2013
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,397
    2,777
    Jan 21, 2010
    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
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    10,069
    2,150
    Nov 17, 2011
    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.
     
  7. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    You missed the extra parenthesis after while:
    Code:
    while ((buffer[i] != ',') && (i<dataLen))
     
  8. anroop

    anroop

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

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    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?
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-