📄 gps.i
字号:
// CodeVisionAVR C Compiler
// (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega64
#pragma used+
sfrb PINF=0;
sfrb PINE=1;
sfrb DDRE=2;
sfrb PORTE=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4; // 16 bit access
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRR0L=9;
sfrb UCSR0B=0xa;
sfrb UCSR0A=0xb;
sfrb UDR0=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e; // 16 bit access
sfrb SFIOR=0x20;
sfrb WDTCR=0x21;
sfrb OCDR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrw ICR1=0x26; // 16 bit access
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28; // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a; // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c; // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb ASSR=0x30;
sfrb OCR0=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TIFR=0x36;
sfrb TIMSK=0x37;
sfrb EIFR=0x38;
sfrb EIMSK=0x39;
sfrb EICRB=0x3a;
sfrb XDIV=0x3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-
// Interrupt vectors definitions
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
/* CodeVisionAVR C Compiler
Prototypes for standard library functions
(C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
*/
#pragma used+
int atoi(char *str);
long int atol(char *str);
float atof(char *str);
void itoa(int n,char *str);
void ltoa(long int n,char *str);
void ftoa(float n,unsigned char decimals,char *str);
void ftoe(float n,unsigned char decimals,char *str);
void srand(int seed);
int rand(void);
void *malloc(unsigned int size);
void *calloc(unsigned int num, unsigned int size);
void *realloc(void *ptr, unsigned int size);
void free(void *ptr);
#pragma used-
#pragma library stdlib.lib
volatile unsigned char sh;
volatile unsigned char buffer[100];
volatile unsigned int i;
volatile unsigned int sectionid;
volatile unsigned char buf[7];
volatile unsigned char section6;
volatile unsigned char sectioncount;
volatile unsigned char buf_sram[100];
volatile unsigned int sram_count;
volatile unsigned int j;
volatile unsigned char sram0;
volatile unsigned char sram1;
volatile unsigned char sram2;
volatile unsigned char sram3;
volatile unsigned int count=0;
volatile unsigned int status;
unsigned char sate;
volatile unsigned long int offset=0x1100;
volatile unsigned long int offset1=0x1100;
volatile unsigned int p;
unsigned char gpscount;
unsigned char engps_alarm;
volatile unsigned int alarm_count;
void gpsreset(void) //GPS复位
{
PORTE.5 =0;
delay_ms(500);
PORTE.5 =1;
delay_ms(500);
}
void initusart0(void) //串口0的初始化
{
(*(unsigned char *) 0x95) =0x06;
UBRR0L=0x07;
(*(unsigned char *) 0x90)=0x00;
UCSR0A = 0x00;
UCSR0B = 0x98;
}
void initusart1(void) //串口1的初始化
{
(*(unsigned char *) 0x9b)=0X00;
(*(unsigned char *) 0x9a)=0X98; //10011000
(*(unsigned char *) 0x9d)=0X06; //00000110
(*(unsigned char *) 0x99)=95;
(*(unsigned char *) 0x98)=0X00;
}
void waikuo(void) //外部扩展的初始化
{
MCUCR=0X80;
(*(unsigned char *) 0x6d)=0X00;
(*(unsigned char *) 0x6c)=0X00;
}
void put_c(char c)
{
while(!(UCSR0A&(1<<5)));
UDR0=c;
}
void write1(unsigned long int add,unsigned char val) //将数据写入相应的地址
{
unsigned char *d;
d=(unsigned char *)(add);
*d=val;
}
char read1(unsigned long int add)
{
unsigned char *t;
t=(unsigned char *)(add);
return *t;
}
void gpsput(unsigned char command)
{
while(!((*(unsigned char *) 0x9b)&(1<<5 )));
(*(unsigned char *) 0x9c)=command;
}
void gpsputs(flash unsigned char *ptr)
{
while (*ptr)
{
gpsput(*ptr++);
}
}
void sramvisible(void)
{
while(j<sram_count){
if(sram0==1){
if(offset==32752){
offset=0x1100;
offset1=0x1100;
sram1=1;
sram0=0;
}
else
{
PORTD=0X10;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram1==1)
{
if(offset==32752)
{
offset=0x1100;
offset1=0x1100;
sram1=0;
sram2=1;
}
else
{
PORTD=0X20;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram2==1)
{
if(offset==32752)
{
offset=0x1100;
offset1=0x1100;
sram2=0;
sram3=1;
}
else
{
PORTD=0X40;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram3==1)
{
if(offset==32752)
{
offset=0x1100;
offset1=0x1100;
sram3=0;
sram0=1;
}
else
{
PORTD=0X80;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
j++;
}
j=0;
offset=offset1+100;
offset1=offset1+100;
sram_count=0;
}
void gprmc(void)
{
gpscount++;
if((sectionid==8||sectionid==9)&&buffer[i]==',') {
buf_sram[sram_count]=0x2c;
sram_count++;
}
if(buffer[i]==',')
sectionid++;
else
{
switch(sectionid)
{
case 2:
if(buffer[i]=='A')
status=1;
if(buffer[i]=='V')
status=0;
break;
case 8:
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 9:
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
default:
break;
}
}
}
void gpgga(void)
{
gpscount++;
if((sectioncount==0||sectioncount==1||sectioncount==2||sectioncount==3||sectioncount==4||sectioncount==5||sectioncount==9||sectioncount==10)&&buffer[i]==',')
{
buf_sram[sram_count]=0x2c;
sram_count++;
}
if(buffer[i]==',')
sectioncount++;
else{
switch(sectioncount)
{
case 1: //shijian
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 2: //weidu
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 3: //n
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 4: //jingdu
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 5: //e
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 7:
if(buffer[i]=='0')
sate=1;
else
sate=0;
break;
case 9: //gaodu
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 10: //danwei
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
default:
break;
}
}
}
void gpvtg(void)
{
gpscount++;
if((section6==7||section6==8)&&buffer[i]==',')
{
buf_sram[sram_count]=0x2c;
sram_count++;
}
if(buffer[i]==',')
section6++;
else
{
switch(section6)
{
case 7:
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
case 8:
buf_sram[sram_count]=buffer[i];
sram_count++;
break;
}
}
if(section6==9&&buffer[i]==',')
{
buf_sram[sram_count]=0x0d;
sram_count++;
buf_sram[sram_count]=0x0a;
sram_count++;
count++;
if(count<1000)//&&status==1)
{sramvisible();
gpscount=0;
}
if(count>=1000)
{
sram0=1;
sram1=0;
sram2=0;
sram3=0;
count=0;
offset=0x1100;
offset1=0x1100;
}
if(status==1&&sate==1)
{
alarm_count++;
if(alarm_count>=4)
engps_alarm=1;
}
}
}
interrupt[31]void usart1_isr(void) //USART1的接收中断。
{
sh=(*(unsigned char *) 0x9c);
buffer[i]=sh;
if(buffer[i]=='C'&&buffer[i-1]=='M'&&buffer[i-2]=='R'&&buffer[i-3]=='P'&&buffer[i-4]=='G'&&buffer[i-5]=='$')
{
sectionid=0;
buf[0]='$';
buf[5]='C';
}
if(buffer[i]==0x0a)
i=0;
if(buffer[i]=='A'&&buffer[i-1]=='G'&&buffer[i-2]=='G'&&buffer[i-3]=='P'&&buffer[i-4]=='G'&&buffer[i-5]=='$')
{
sectioncount=0;
buf[0]='$';
buf[4]='A';
}
if(buffer[i]=='G'&&buffer[i-1]=='T'&&buffer[i-2]=='V'&&buffer[i-3]=='P'&&buffer[i-4]=='G'&&buffer[i-5]=='$')
{
section6=0;
buf[0]='$';
buf[5]='G';
}
if(buf[0]=='$'&&buf[4]=='A')
{ gpgga();
}
if(buf[0]=='$'&&buf[5]=='C')
{ gprmc();
}
if(buf[5]=='G'&&buf[0]=='$')
gpvtg();
i++;
}
void gps5s(void)
{
gpsputs("$PSRF103,2,0,0,1*26\r\n");
delay_ms(500);
gpsputs("$PSRF103,3,0,0,1*27\r\n");
delay_ms(500);
gpsputs("$PSRF103,0,0,255,1*26\r\n");
delay_ms(500);
gpsputs("$PSRF103,4,0,255,1*22\r\n");
delay_ms(500);
gpsputs("$PSRF103,5,0,255,1*23\r\n");
delay_ms(500);
}
void main(void)
{
#asm("sei")
gpsreset();
sram0=1;
initusart0();
initusart1();
PORTB=0X40;
DDRB=0X60;
PORTD=0X00;
PORTC=0X80;
DDRC=0X80;
DDRD=0XF3;
DDRE=0X20;
waikuo();
sram0=1;
sram1=0;
sram2=0;
sram3=0;
gps5s();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -