本人毕设: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);
<
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
工作量一样
一周热门 更多>