-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
127 lines (110 loc) · 4.22 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "usmart.h"
#include "usart3.h"
#include "gps.h"
//ALIENTEK 探索者STM32F4开发板扩展实验16
//ATK-S1216F8 GPS模块测试实验
//技术支持:www.openedv.com
//广州市星翼电子科技有限公司
u8 USART1_TX_BUF[USART3_MAX_RECV_LEN]; //串口1,发送缓存区
nmea_msg gpsx; //GPS信息
__align(4) u8 dtbuf[50]; //打印缓存器
const u8*fixmode_tbl[4]={"Fail","Fail"," 2D "," 3D "}; //fix mode字符串
//显示GPS定位信息
void Gps_Msg_Show(void)
{
float tp;
POINT_COLOR=BLUE;
tp=gpsx.longitude;
sprintf((char *)dtbuf,"Longitude:%.5f %1c ",tp/=100000,gpsx.ewhemi); //得到经度字符串
LCD_ShowString(30,120,200,16,16,dtbuf);
tp=gpsx.latitude;
sprintf((char *)dtbuf,"Latitude:%.5f %1c ",tp/=100000,gpsx.nshemi); //得到纬度字符串
LCD_ShowString(30,140,200,16,16,dtbuf);
tp=gpsx.altitude;
sprintf((char *)dtbuf,"Altitude:%.1fm ",tp/=10); //得到高度字符串
LCD_ShowString(30,160,200,16,16,dtbuf);
tp=gpsx.speed;
sprintf((char *)dtbuf,"Speed:%.3fkm/h ",tp/=1000); //得到速度字符串
LCD_ShowString(30,180,200,16,16,dtbuf);
if(gpsx.fixmode<=3) //定位状态
{
sprintf((char *)dtbuf,"Fix Mode:%s",fixmode_tbl[gpsx.fixmode]);
LCD_ShowString(30,200,200,16,16,dtbuf);
}
sprintf((char *)dtbuf,"GPS+BD Valid satellite:%02d",gpsx.posslnum); //用于定位的GPS卫星数
LCD_ShowString(30,220,200,16,16,dtbuf);
sprintf((char *)dtbuf,"GPS Visible satellite:%02d",gpsx.svnum%100); //可见GPS卫星数
LCD_ShowString(30,240,200,16,16,dtbuf);
sprintf((char *)dtbuf,"BD Visible satellite:%02d",gpsx.beidou_svnum%100); //可见北斗卫星数
LCD_ShowString(30,260,200,16,16,dtbuf);
sprintf((char *)dtbuf,"UTC Date:%04d/%02d/%02d ",gpsx.utc.year,gpsx.utc.month,gpsx.utc.date); //显示UTC日期
LCD_ShowString(30,280,200,16,16,dtbuf);
sprintf((char *)dtbuf,"UTC Time:%02d:%02d:%02d ",gpsx.utc.hour,gpsx.utc.min,gpsx.utc.sec); //显示UTC时间
LCD_ShowString(30,300,200,16,16,dtbuf);
}
int main(void)
{
u16 i,rxlen;
u16 lenx;
u8 key=0XFF;
u8 upload=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口波特率为115200
usart3_init(384200); //初始化串口3波特率为115200
LED_Init(); //初始化LED
LCD_Init(); //LCD初始化
KEY_Init(); //按键初始化
usmart_dev.init(168); //初始化USMART
POINT_COLOR=RED;
LCD_ShowString(30,20,200,16,16,"ALIENTEK STM32F1 ^_^");
LCD_ShowString(30,40,200,16,16,"S1216F8-BD TEST");
LCD_ShowString(30,60,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,80,200,16,16,"KEY0:Upload NMEA Data SW");
LCD_ShowString(30,100,200,16,16,"NMEA Data Upload:OFF");
if(SkyTra_Cfg_Rate(5)!=0) //设置定位信息更新速度为5Hz,顺便判断GPS模块是否在位.
{
LCD_ShowString(30,120,200,16,16,"SkyTraF8-BD Setting...");
do
{
usart3_init(9600); //初始化串口3波特率为9600
SkyTra_Cfg_Prt(3); //重新设置模块的波特率为38400
usart3_init(38400); //初始化串口3波特率为38400
key=SkyTra_Cfg_Tp(100000); //脉冲宽度为100ms
}while(SkyTra_Cfg_Rate(5)!=0&&key!=0);//配置SkyTraF8-BD的更新速率为5Hz
LCD_ShowString(30,120,200,16,16,"SkyTraF8-BD Set Done!!");
delay_ms(500);
LCD_Fill(30,120,30+200,120+16,WHITE);//清除显示
}
while(1)
{
delay_ms(1);
if(USART3_RX_STA&0X8000) //接收到一次数据了
{
rxlen=USART3_RX_STA&0X7FFF; //得到数据长度
for(i=0;i<rxlen;i++)USART1_TX_BUF[i]=USART3_RX_BUF[i];
USART3_RX_STA=0; //启动下一次接收
USART1_TX_BUF[i]=0; //自动添加结束符
GPS_Analysis(&gpsx,(u8*)USART1_TX_BUF);//分析字符串
Gps_Msg_Show(); //显示信息
if(upload)printf("\r\n%s\r\n",USART1_TX_BUF);//发送接收到的数据到串口1
}
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
upload=!upload;
POINT_COLOR=RED;
if(upload)LCD_ShowString(30,100,200,16,16,"NMEA Data Upload:ON ");
else LCD_ShowString(30,100,200,16,16,"NMEA Data Upload:OFF");
}
if((lenx%500)==0)
LED0=!LED0;
lenx++;
}
}