📄 main._c
字号:
/*
###############################################################################
Include Part
###############################################################################
*/
#include <iom32v.h> // mega16 register definition file
#include <lcd.h> // LCD driver file
#include "def.h" // Type definition file
#include <macros.h>
#include <serial.h> //serial port driver file
/*
##############################################################
define part
##############################################################
*/
// char rcv_buf[1024];
char time[10];
char status;
char latitude[9];
char NSind;
char longtitude[10];
char EWind;
char date[6];
/*
###############################################################################
Function Prototype Definition Part
###############################################################################
*/
void port_init(void);
void init_devices(void);
void GpsDataParse(void);
void Parse (void);
void convert (void);
/*
###############################################################################
Function Implementation Part
###############################################################################
*/
void main (void)
{
int i=0;
//initial the MCU
init_devices();
while (1)
{
// for (i=0;i<3000;i++);
GpsDataParse(); //get data
display(); //display
}
}
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFC;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x83;
PORTD = 0x00;
DDRD = 0x9C;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
//all peripherals are now initialized
SEI();
}
void GpsDataParse(void)
{
char head[3];
char temp;
//CLI();
temp=Read_buf();
while (temp != '$')
temp=Read_buf();
temp=Read_buf();//first and second character are "GPXXX"
temp=Read_buf();
//get the header
head[0]=Read_buf();
head[1]=Read_buf();
head[2]=Read_buf();
if(head[0]=='R' && head[1]=='M' && head[2]=='C')
{
Parse ();
return ;
}
}
/**********************************************************************
* get information from GPRMC
*Description: need array to place time,date, latitude,longtitude
size of the array
************************************************************************/
void Parse (void)
{
char temp;
int i=0;
//read time
temp=Read_buf();// jump over ','
temp=Read_buf();
while(i<10)
{
time[i++]=temp;
temp=Read_buf();
}
convert ();
//read status
status=Read_buf();
if (status=='V')
return;
//read latitude
temp=Read_buf();//read the ','
i=0;
while(i<9)
latitude[i++]=Read_buf();
//read NSindicator
temp=Read_buf();//read the ','
NSind=Read_buf();
temp=Read_buf();//read the ','
//read longtitude
i=0;
while(i<10)
longtitude[i++]=Read_buf();
//read EWindicator
temp=Read_buf();//read the ','
EWind=Read_buf();
i=0;
while (i<3)
{
temp=Read_buf();//read the ','
while (temp!=',')
temp=Read_buf();
i++;
}
for (i=0;i<6;i++)
{
date[i]=Read_buf();
}
}
void convert (void)
{
if (time[1]<1)
time[1]=time[1]+8;
else
{
time[1]=time[1]+8-10;
time[0]=time[0]+1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -