Har någon en tanke?
Jag använder:
*pic16f690 på ett PICKIT2
*EM-406 GPS-modul, output är TTL
*interna 4Mhz klockan
*baudrate 4800
Jag tycker att det är riktigt märkligt!
Kod: Markera allt
#include <pic.h>
#include <htc.h>
#include "lcd.h"
#include "delay.h"
__CONFIG(INTIO & WDTDIS & PWRTDIS & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);
unsigned int BUFFMAX = 80;
unsigned char gps_string[80]; //Databuffer
//char gps_string2[] = "$GPRMC,224204.000,A,5535.3985,N,01300.8159,E,6.83,258.07,040810,,*0F";
int head = 0;
void usart(void){
TRISB = 0XFF;
#asm
bcf _TRISB,7 //RB7 USART-output
#endasm
TRISC = 0X00; //Just for debug
PORTC = 0; //-||-
ANSELH = 0x00; //All pins digital
SPBRG = 51; //4800 bps
BRGH = 1;
TXEN = 1; //Allows sending
SYNC = 0; //The SYNC bit should be cleared to select asynchronous operation.
SPEN = 1; //SPEN bit is used to enable the entire serial port
CREN = 0;
CREN = 1; //Allows receiving
GIE = 1; //*Interrupts
PEIE = 1;
TXIE = 0; //Disable transmit interrupt
RCIE = 1; //Enable receive interrupt
}
void putch(unsigned char c){
while(!TXIF) //Set when TXREG is empty
continue; //Continue looping while TXREG is not available
TXREG = c; //Put character to be sent onto TXREG
}
enum {START_WAIT, RECEIVING, MSG_RECEIVED} state = START_WAIT;
void interrupt pic_isr(void) {
unsigned char c;
if((RCIE)&&(RCIF)){ // If this interrupt was generated by a receive character
c = RCREG;
switch(state){
case START_WAIT:
if(c == '$'){
head = 0;
state = RECEIVING;
}
break;
case RECEIVING:
if(c == '*'){
state = MSG_RECEIVED;
}
else{
gps_string[head] = c;
if(++head>=BUFFMAX){
state = START_WAIT;
}
}
break;
}
}
if(OERR){ // If we missed a character (Overrun Error)
CREN = 0; // Reset the error bit
CREN = 1;
}
}
void main(void){
usart(); //Initialize USART
while(1){
if(state == MSG_RECEIVED){
for(int i = 0; i <= head; i++){
putch(gps_string[i]);
}
state = START_WAIT;
}
}
}