📄 untitled.c~
字号:
#include<mega64.h>
#include<delay.h>
#include<stdlib.h>
#define GPS_RST PORTE.5 //1 DDRE=00100010
#define GPS_TX PORTD.2 //0 DDRD=11111011
#define GPS_RX PORTD.3 //1 DDRB=01100000
#define SHDN_232 PORTB.6 //1
#define EN_232 PORTB.5 //1
#define RX_EPOS PORTE.0 //0
#define TX_EPOS PORTE.1 //1
#define FE0 4
#define DOR0 3
#define UPE0 2
#define UDRE0 5
#define VREF 3.3
#define FE1 4
#define DOR1 3
#define UPE1 2
#define UDRE1 5
#define RXC1 7
#define SRAM0 PORTD.4
#define SRAM1 PORTD.5
#define SRAM2 PORTD.6
#define SRAM3 PORTD.7
volatile unsigned char th;
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;
unsigned char alarm;
volatile unsigned int n;
volatile unsigned long int offset=0x1100;
volatile unsigned long int offset1=0x1100;
volatile unsigned char str;
volatile unsigned int p;
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char gpscount;
volatile unsigned gps_alarm;
volatile unsigned power_alarm;
volatile unsigned position_alarm;
unsigned char power_disconnect;
unsigned char engps_alarm;
unsigned char position_breakaway;
unsigned char all;
volatile unsigned int alarm_count;
volatile unsigned char gps_gdr;
volatile unsigned char gps_gsc;
volatile unsigned char gps_sramvisible;
void gpsreset(void) //GPS复位
{
PORTD=0X00;
PORTE=0X00;
GPS_RST=0;
delay_ms(500);
GPS_RST=1;
delay_ms(500);
PORTE=0X10;
PORTD=0X01;
}
void initusart0(void) //串口0的初始化
{
UCSR0C =0x06;
UBRR0L=0x07;
UBRR0H=0x00;
UCSR0A = 0x00;
UCSR0B = 0x98;
}
void initusart1(void) //串口1的初始化
{
UCSR1A=0X00;
UCSR1B=0X98; //10011000
UCSR1C=0X06; //00000110
UBRR1L=95;
UBRR1H=0X00;
}
void waikuo(void) //外部扩展的初始化
{
MCUCR=0X80;
XMCRA=0X00;
XMCRB=0X00;
}
void put_c(char c)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=c;
}
unsigned int read_adc(unsigned char abc_input)
{
ADMUX=abc_input;
ADCSRA=0Xc6;
while((ADCSRA&0X10)==0);
ADCSRA&=~(1<<ADIF);
ADCSRA&=~(1<<ADEN);
return ADCW;
}
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(!(UCSR1A&(1<<UDRE1)));
UDR1=command;
}
void gpsputs(flash unsigned char *ptr)
{
while (*ptr)
{
gpsput(*ptr++);
}
}
void initadc(void)
{
ADMUX=0X00;
ADCSRA=0X86;
}
void inttostr(unsigned int t)
{
unsigned char o;
unsigned char u;
unsigned char q;
unsigned char v;
o=t/1000+0x30;;
u=t%1000/100+0x30;;
q=t%100/10+0x30;
v=t%10+0x30;
gpsput(o);
gpsput(u);
gpsput(q);
gpsput(v);
}
void sramvisible(void)
{
while(j<sram_count){
if(sram_count<50||sram_count>70)
break;
if(sram0==1){
if(offset==32700){
offset=0x1100;
offset1=0x1100;
sram1=1;
sram0=0;
}
else
{
PORTD=0X11;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram1==1)
{
if(offset==32700)
{
offset=0x1100;
offset1=0x1100;
sram1=0;
sram2=1;
}
else
{
PORTD=0X21;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram2==1)
{
if(offset==32700)
{
offset=0x1100;
offset1=0x1100;
sram2=0;
sram3=1;
}
else
{
PORTD=0X41;
write1(offset,buf_sram[j]);
p=read1(offset);
put_c(p);
offset++;
}
}
if(sram3==1)
{
if(offset==32700)
{
offset=0x1100;
offset1=0x1100;
sram3=0;
sram0=1;
}
else
{
PORTD=0X81;
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -