专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
TI
移植下程序
2019-07-24 17:27
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
7541
5
962
gps信息采集与完好性监测系统设计,现有一51单片机程序,老师要求用msp430f149做,跪求大神帮忙移植下。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
jiaxw
2019-07-24 19:01
#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;
加载中...
查看其它5个回答
一周热门
更多
>
相关问题
CPLD的方波输出
4 个回答
11个版本Quartus II 软件下载,安装包网盘合集,附教程,47G!
20 个回答
请大家帮忙到21IC发展大家谈支持我申请新版面
20 个回答
【通知】21ic中国电子网服务条款 (所有人员必读)
1 个回答
满载而归乙亥年,大展鸿途庚子年---集签赢好礼
20 个回答
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
TI
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#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;
一周热门 更多>