📄 regps.c
字号:
//ICC-AVR application builder : 2008-2-22 10:46:36
// Target : M8
// Crystal: 7.3728Mhz
//2008/02/25
//DATA :201537,28.416216,N,115.567455,E,0.00,250208,
#include <iom8v.h>
#include <macros.h>
unsigned char rermc[70];
unsigned char crmc[10];
unsigned char new_drmc[50];
unsigned char rei2,cmi,cmi2,legn,datatrue,truei=1;
void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
void sendviwe(unsigned char x[],unsigned char i)
{unsigned char s;
for(s=0;s<i;s++)
{
while ( !( UCSRA & (1<<UDRE)) );
UDR=x[s];
}
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x2F; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
//uart has received a character in UDR
unsigned char rei,yy;
rei=UDR;
if(truei)
{
switch(rei)
{
case '$':
cmi2=1;
break;
case 'G':
if(cmi2) cmi2=2;
break;
case 'P':
if(cmi2==2) cmi2=3;
break;
case 'R':
if(cmi2==3) cmi2=4;
break;
case 'M':
if(cmi2==4) cmi2=5;
break;
case 'C':
if(cmi2==5) cmi2=6;
break;
case ',':
if(cmi2==6) cmi2=7;
break;
}
if(cmi2==7) truei=0;//检测到RMC的头
}
else
{
if(rei!=0x0a) rermc[rei2++]=rei;//没到数据结尾,保存下来
else //到数据结尾
{
rei2=0;
truei=1;
cmi2=0;
cmi=1;
}
}
}
void jinwei_excharge(unsigned char i)//经纬度转化为正常读数
{ unsigned char t;
if(i)
{
t=crmc[4];
crmc[4]=crmc[3];
crmc[3]=crmc[2];
crmc[2]=t;
}
else
{
t=crmc[5];
crmc[5]=crmc[4];
crmc[4]=crmc[3];
crmc[3]=t;
}
}
void timecharge(void) //change time to beijing time
{
unsigned char x;
x=crmc[0]-0x30;
if(x>0) x=x*10;
x=x+(crmc[1]-0x30);
x=x+0x08;
crmc[0]=x/10+0x30;
crmc[1]=x%10+0x30;
}
void getdata(unsigned char sx)//
{ unsigned char sss,ssx=0,lsx;
lsx=sx+11;
for(;sx<lsx;sx++)
{
sss=rermc[sx];
if(sss==',') break;
crmc[ssx]=sss;
ssx++;
}
legn=sx;
}
void newrmc()
{
unsigned char wx,cx=0,lwx,llwx;
getdata(0);//get time
timecharge();//
for(wx=0;wx<6;wx++)
{
new_drmc[wx]=crmc[wx];
}
new_drmc[wx]=',';//real time
getdata(legn+1);//get data true
if(crmc[0]=='A') datatrue=1;
else datatrue=0;
getdata(legn+1);//get 纬度
jinwei_excharge(1);
wx=wx+1;
lwx=wx+9;
for(;wx<lwx;wx++)
{
new_drmc[wx]=crmc[cx];
cx++;
}
new_drmc[wx]=',';//
getdata(legn+1);//n/s
new_drmc[wx+1]=crmc[0];//
new_drmc[wx+2]=',';//
getdata(legn+1);//get jingdu
jinwei_excharge(0);
cx=0;
wx=wx+3;
lwx=wx+10;
for(;wx<lwx;wx++)
{
new_drmc[wx]=crmc[cx];
cx++;
}
new_drmc[wx]=',';//
getdata(legn+1);//w/e
new_drmc[wx+1]=crmc[0];//
new_drmc[wx+2]=',';//
llwx=legn+1;//save
getdata(legn+1);//speed地面速率
cx=0;
wx=wx+3;
lwx=legn-llwx+wx;//速度有效长度
for(;wx<lwx;wx++)
{
new_drmc[wx]=crmc[cx];
cx++;
}
new_drmc[wx]=',';//
getdata(legn+1);//地面航向
getdata(legn+1);//date
cx=0;
wx=wx+1;
lwx=wx+6;
for(;wx<lwx;wx++)
{
new_drmc[wx]=crmc[cx];
cx++;
}
//new_drmc[wx]=',';//
new_drmc[wx]=0x0a;//
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while(1)
{
if(cmi)
{
CLI();
newrmc();
sendviwe(new_drmc,legn-5);
SEI();
cmi=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -