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();
}
}
}
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();
}
}
}