这一个MSP430单片机程序。从串口接收GPS数据,经过单片机处理后,得到有用数据,将这些有用数据通过串口0发给上位机。我是430单片机初学者,本程序肯定又去多不合理的地方,请高手指点。程序代码如下:
#include <msp430.h>
#include "UART0.h"
#include "UART1.h"
unsigned char GPS[500] = {0},TIME[8] = {0},LAT[11] = {0},
LON[12] = {0},QUA[1] = {0},STA[1] = {0},ALT[8] = {0},
AVL_GPS[46] = {0},Hour = 0,HH = 0,HL = 0,FLAG = 0;
unsigned int g = 0,p = 0,s = 0;
void main()
{
WDTCTL = WDTPW + WDTHOLD;
InitUART0();
InitUART1();
while (1)
{
for(g = 0; g <500; g++)
{
GPS[g] = Get1Char1();
}
for(g = 0; g < 500; g++)
{
if((g < 442) && (GPS[g] == 'G') && (GPS[g + 1] == 'A')&& (GPS[g + 18] == '.'))
{
FLAG = 1;
/*****************当前时间******************/
HH = GPS[g + 3];
HL = GPS[g + 4];
Hour = (HH - 0x30) * 10 + (HL - 0x30) + 0x08;
Hour %= 24;
TIME[0] = Hour/10 + 0x30;
TIME[1] = Hour%10 + 0x30;
TIME[2] = ':';
TIME[3] = GPS[g + 5];
TIME[4] = GPS[g + 6];
TIME[5] = ':';
TIME[6] = GPS[g + 7];
TIME[7] = GPS[g + 8];
/*****************当前纬度*****************/
for(s = 0;s < 9;s++)
{
LAT[s] = GPS[g + s + 14];
}
LAT[9] = 0x20;
LAT[10] = GPS[g + 24];
/****************当前经度*****************/
for(s = 0;s < 10;s++)
{
LON[s] = GPS[g + s + 26];
}
LON[10] = 0x20;
LON[11] = GPS[g + 37];
/****************定位质量指示************/
QUA[0] = GPS[g + 39];
/****************使用卫星数量************/
STA[0] = GPS[g + 41];
/**********天线离海平面的高度************/
for(s = 0;s < 6;s++)
{
ALT[s] = GPS[g + s + 48];
}
ALT[6] = 0x20;
ALT[7] = GPS[g + 55];
/****将获得的有效值存放在AVL_GPS[]中****/
for(p = 0;p < 8;p++)
{
AVL_GPS[p] = TIME[p];
}
AVL_GPS[8] = ',';
for(p = 9;p < 20;p++)
{
AVL_GPS[p] = LAT[p - 9];
}
AVL_GPS[20] = ',';
for(p = 21;p < 33;p++)
{
AVL_GPS[p] = LON[p - 21];
}
AVL_GPS[33] = ',';
for(p = 34;p < 42;p++)
{
AVL_GPS[p] = ALT[p - 34];
}
AVL_GPS[42] = ',';
AVL_GPS[43] = STA[0];
AVL_GPS[44] = ',';
AVL_GPS[45] = QUA[0];
}
}
if(FLAG == 1)
{
SendEnter0();
PutString0("/*****GPS测量成功,开始显示GPS数据*****/");
SendEnter0();
SendEnter0();
PutString0("北京时间: ");
for(g = 0; g < 8; g++)
{
Send1Char0(TIME[g]);
}
SendEnter0();
PutString0("当前纬度: ");
for(g = 0; g < 11; g++)
{
Send1Char0(LAT[g]);
}
SendEnter0();
PutString0("当前经度: ");
for(g = 0; g < 12; g++)
{
Send1Char0(LON[g]);
}
SendEnter0();
PutString0("海拔高度: ");
for(g = 0; g < 8; g++)
{
Send1Char0(ALT[g]);
}
SendEnter0();
PutString0("卫星数量: ");
Send1Char0(STA[0]);
SendEnter0();
PutString0("定位质量: ");
Send1Char0(QUA[0]);
SendEnter0();
PutString0("组合数据: ");
for(g = 0; g < 46; g++)
{
Send1Char0(AVL_GPS[g]);
}
SendEnter0();
SendEnter0();
PutString0("/*****有效GPS数据显示完毕*****/");
SendEnter0();
SendEnter0();
SendEnter0();
}
else
PutString0("GPS测量失败!");
}
} |