gps信息采集与完好性监测系统设计,现有一51单片机程序,老师要求用msp430f149做,跪求大神帮忙移植下。
#include <reg52.h>
#include <absacc.h>
#include <intrins.h>
#include <header.h>
#include <math.h>
#define D_PORT P0
sbit RS =P2^0;
sbit RW =P2^1;
sbit E =P2^2;
#define LCD_BUS P0
#define LCD_COMMAND 0
#define LCD_DATA 1
unsigned char data GPS_buffer[60];
unsigned char xdata GPS_Data_num=0;
unsigned char data GPS_utc_buffer[7];
unsigned char xdata GPS_utc_len=0;
unsigned char xdata GPGRS_datalen[12];
unsigned char xdata comma_number= 0;
unsigned char xdata sv_status_flag=0;
unsigned char data display_square_error[6]=0;
GPS_DATA_SH xdata posdata_shu;
void wait_free()
{
unsigned char retb;
do{
D_PORT=0xff;
E=1;
retb=D_PORT;
}while((retb&0x80)!=0);
}
void write_comm(unsigned char cmd_dat,bit cd)
{
wait_free();
if(cd)RS=1;
else RS=0;
RW=0;
E=1;
D_PORT=cmd_dat;
}
void LCD_SetInput(unsigned char InputMode)
{
write_comm( 0x04|InputMode,0);
}
void LCD_SetDisplay(unsigned char DisplayMode)
{
write_comm(0x08|DisplayMode,0);
}
void delay()
{
unsigned int i,k;
for(i=0;i<100;i++)
for(k=0;k<100;k++);
}
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
write_comm(0x80|x,LCD_COMMAND);
if(y==1)
write_comm(0x90|x,LCD_COMMAND);
}
void Print(unsigned char *str,unsigned char len)
{
unsigned char i;
for(i=0;i<len;i++)
{
write_comm(*str++,1);
}
}
void LCD_ShowString(unsigned char line, unsigned char col, unsigned char *str,unsigned char len)
{
GotoXY(col,line);
Print(str,len);
}
void seria0() interrupt 4 using 2
{
unsigned char data RcvChar;
unsigned char data dataHeader[6]="$GPGRS";
if(RI)
{
RI = 0 ;
RcvChar=SBUF;
if(!posdata_shu.ful)
{
if(posdata_shu.check >=6 )
{
if(RcvChar!=0x0a)
{ P1=0xf8;
*(posdata_shu.buf+posdata_shu.off) = RcvChar;
posdata_shu.off ++;
}
else
{
P1=0xf8;
posdata_shu.ful = 1;
posdata_shu.val = 1;
posdata_shu.check = 0;
}
}
else
{
if(*(dataHeader+posdata_shu.check) == RcvChar)
{ posdata_shu.check++;
}
else
{
posdata_shu.check= 0;
posdata_shu.off = 0 ;
}
}
}
else
{
;
}
}
}
void sv_status(unsigned char sv_number,float sv_sseerror)
{
unsigned char sv_status_temp;
switch(sv_number)
{
case 5:
if(sv_sseerror>31.960)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 6:
if(sv_sseerror>24.088)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 7:
if(sv_sseerror>20.612)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 8:
if(sv_sseerror>18.551)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 9:
if(sv_sseerror>17.153)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 10:
if(sv_sseerror>16.125)
{
sv_status_temp=0x55;
}
case 11:
if(sv_sseerror>15.331)
{
sv_status_temp=0x55;
}
else
{
sv_status_temp=0xaa;
}
break;
case 12:
if(sv_sseerror>14.693)
{
sv_status_temp=0x55;
}
break;
}
sv_status_flag=sv_status_temp;
}
//////////////////////////////////////////////////////////////
unsigned char *get_in_gps(unsigned char *paddr,unsigned char n)
{
unsigned char *return_p;
unsigned char i=0;
return_p = paddr;
while(1)
{
if(*return_p == ',')
{
i++;
}
return_p++;
if(i == n)
{
break;
}
}
return return_p;
}
unsigned char convertdata(unsigned char ch)
{
if((ch>=0x30) &&(ch<=0x39))
return (ch-0x30);
if((ch>=0x41) &&(ch<=0x5a))
return (ch-0x41+0x0a);
if((ch>=0x61)&&(ch<=0x7a))
return(ch-0x61+0x0a);
return 0;
}
char GPS_Data_verify(unsigned char *paddr,unsigned char len)
{
unsigned char comma = 0;
unsigned char i;
unsigned char index= 0;
unsigned char index1= 0;
unsigned char hour;
unsigned char *pdat;
unsigned char crc = 0x4b;
unsigned char temp1;
unsigned char temp2;
unsigned char *pdat_buffer;
pdat_buffer=paddr;
for(i=0;i<len;i++)
{
temp1=*pdat_buffer;
temp2=*(pdat_buffer+1);
if((*pdat_buffer ==',')&&(*(pdat_buffer+1)!=','))
{
comma_number++;
}
pdat_buffer++;
}
comma_number=comma_number-3;
pdat = get_in_gps(paddr, 1);
for(i=0;i<6;i++)
{
GPS_utc_buffer[index1++] = *(pdat+i);
GPS_utc_len++;
}
hour = (*pdat-0x30)*10+*(pdat+1)-0x30;
hour +=8;
hour %=24;
*pdat = hour/10+0x30;
*(pdat+1) = hour%10+0x30;
for(i=0;i<6;i++)
{
GPS_buffer[index++] = *(pdat+i);
}
for(i=0;i<comma_number;i++)
{
pdat = get_in_gps(paddr,(3+i));
while(*pdat !=',')
{
if(*pdat=='-')
{
pdat++;
}
else
{
GPS_buffer[index++] = *pdat;
pdat++;
GPGRS_datalen++;
}
}
}
GPS_Data_num=index;
return index;
}
void gps_data_convert(void)
{
unsigned char err_flag=0;
unsigned char i=0;
unsigned char index=0;
float range_error[12];
float squre_error=0;
float sse_error=0;
float squre_error_yushu=0;
unsigned char squre_integer=0;
unsigned char squre_integer_high=0;
unsigned char squre_integer_low=0;
unsigned int squre_temp=0;
unsigned char squre_decimal_inte1=0;
unsigned char squre_decimal_yushu=0;
unsigned char squre_decimal_inte2=0;
unsigned char squre_decimal_inte3=0;
if(posdata_shu.val==1)
{
P1=0xfa;
posdata_shu.val=0;
err_flag = GPS_Data_verify(posdata_shu.buf,posdata_shu.off);
if(err_flag== -1)
{
P1=0xfb;
posdata_shu.ful = 0;
posdata_shu.off=0;
return;
}
else if(err_flag ==0)
{ P1=0xfc;;
posdata_shu.ful = 0;
posdata_shu.val = 0;
posdata_shu.off=0;
return;
}
index=6;
for(i=0;i<comma_number;i++)
{
if(GPGRS_datalen==4)
{
range_error=((convertdata(GPS_buffer[index]))*10+convertdata(GPS_buffer[index+1])+(convertdata(GPS_buffer[index+3]))*0.1);
index=index+4;
}
else if (GPGRS_datalen==3)
{
range_error=(convertdata(GPS_buffer[index])+convertdata(GPS_buffer[index+2])*0.1);
index=index+3;
}
squre_error=squre_error+range_error*range_error;
}
sse_error=sqrt(squre_error/(comma_number-4));
squre_integer=(int)sse_error;
if(squre_integer>9)
{
squre_integer_high=squre_integer/10;
squre_integer_low=squre_integer%10;
display_square_error[0]=squre_integer_high|0x30;
}
else
{
squre_integer_high=0;
squre_integer_low=squre_integer;
display_square_error[0]=0x20;
}
////////////////////////////////////////////////
squre_error_yushu=sse_error-squre_integer;
squre_temp=squre_error_yushu*1000;
squre_decimal_inte1=squre_temp/100;
squre_decimal_yushu=squre_temp%100;
squre_decimal_inte2=squre_decimal_yushu/10;
squre_decimal_inte3=squre_decimal_yushu%10;
display_square_error[1]=squre_integer_low|0x30;
display_square_error[2]='.';
display_square_error[3]=squre_decimal_inte1|0x30;
display_square_error[4]=squre_decimal_inte2|0x30;
display_square_error[5]=squre_decimal_inte3|0x30;
///////////////////////////////////////////////////
sv_status(comma_number,sse_error);
//////////////////////////////////////////////
P1=0xfd;;
posdata_shu.val = 1;
}
else
{
;
}
}
void main(void)
{
unsigned char i;
//unsigned char j,k;
//unsigned char temp;
serial_init();
pps_init();
delay();
delay();
delay();
delay();
delay();
delay();
write_comm(0x30,0);
delay();
delay();
write_comm(0x30,0);
delay();
delay();
delay();
write_comm(0x0C,0);
delay();
delay();
write_comm(0x01,0);
delay();
delay();
delay();
delay();
delay();
write_comm(0x06,0);
delay();
delay();
EA = 1;
P1=0xf8;
posdata_shu.check= 0;
posdata_shu.off = 0 ;
posdata_shu.ful = 0;
posdata_shu.val=0;
for(i=0;i<12;i++)
{
GPGRS_datalen=0;
}
for(i=0;i<5;i++)
{
display_square_error=0;
}
while(1)
{
gps_data_convert();
if (posdata_shu.val==1)
{
P1=0xf8;
for(i=0;i<posdata_shu.off;i++)
{ TI=0;
SBUF=*(posdata_shu.buf+i);
*(posdata_shu.buf+i)=0;
while(TI==0);
TI=0;
}
posdata_shu.val=0;
posdata_shu.ful = 0;
posdata_shu.off=0;
LCD_ShowString(0,4,display_square_error,6);
LCD_ShowString(0,7,"米",2);
if(sv_status_flag==0xaa)
{
LCD_ShowString(1,5,"无故障",6);
}
else if(sv_status_flag==0x55)
{
LCD_ShowString(1,5,"有故障",6);
}
for(i=0;i<5;i++)
{
display_square_error=0;
}
comma_number=0;
for(i=0;i<12;i++)
{
GPGRS_datalen=0;
}
}
LCD_ShowString(0,0,"伪距SSE:",8);
LCD_ShowString(1,0,"监测结果:",9);
}
}
//header.h
void serial_init()
{SCON = 0x50;
TMOD |= 0x20;
TH1 = TL1 = 0XFD;
TR1 = 1;
PS = 1 ;
ES = 1;
PCON = 0x00; }
void pps_init()
{IT1 = 1;
EX1 = 1; }
typedef struct
{
unsigned char check;
unsigned char off;
unsigned char val;
unsigned char ful;
unsigned char buf[80];
}GPS_DATA_SH; |
|