The actual picture produced is as follows:
The microcontroller source program is as follows:
#include "main.h"
#include "LCD1602.h"
#include "GPS.h"
//Define variables
unsigned char KEY_NUM = 0;
bit Page = 0;
unsigned char xdata Display_GPGGA_Buffer[68];
unsigned char xdata Display_GPRMC_Buffer[68];
bit Flag_OV = 0;
bit Flag_Calc_GPGGA_OK = 0;
bit Flag_Calc_GPRMC_OK = 0;
//****************************************************
//Main function
//****************************************************
void main()
{
unsigned char i = 0;
Init_LCD1602();
LCD1602_write_com(0x80); //Pointer setting
LCD1602_write_word("Welcome to use!");
Delay_ms(1000);
Uart_Init();
while(1)
{
Scan_Key();
if(Flag_GPS_OK == 1 && RX_Buffer[4] == 'G' && RX_Buffer[6] == ',' && RX_Buffer[13] == '.') //Confirm whether the "GPGGA" frame data is received
{
for( i = 0; i < 68 ; i++)
{
Display_GPGGA_Buffer[i] = RX_Buffer[i];
}
Hour = (Display_GPGGA_Buffer[7]-0x30)*10+(Display_GPGGA_Buffer[8]-0x30)+8; //Convert UTC time to Beijing time UTC+8
//0x30 is converted from ASCII to digital
if( Hour >= 24) // Overflow
{
Hour %= 24; //Get the current Hour
Flag_OV = 1; //Date carry
}
else
{
Flag_OV = 0;
}
Min_High = Display_GPGGA_Buffer[9];
Min_Low = Display_GPGGA_Buffer[10];
Sec_High = Display_GPGGA_Buffer[11];
Sec_Low = Display_GPGGA_Buffer[12];
Flag_Calc_GPGGA_OK = 1;
}
if(Page == 0 && Flag_Calc_GPGGA_OK == 1)
{
LED1 = ~LED1;
Flag_Calc_GPGGA_OK = 0;
LCD1602_write_com(0x80); //Set pointer
LCD1602_write_data(Hour/10+0x30);
LCD1602_write_data(Hour%10+0x30);
LCD1602_write_data(':');
LCD1602_write_data(Min_High);
LCD1602_write_data(Min_Low);
LCD1602_write_data(':');
LCD1602_write_data(Sec_High);
LCD1602_write_data(Sec_Low);
LCD1602_write_word(" ");
LCD1602_write_data(Display_GPGGA_Buffer[54]);
LCD1602_write_data(Display_GPGGA_Buffer[55]);
LCD1602_write_data(Display_GPGGA_Buffer[56]);
LCD1602_write_data(Display_GPGGA_Buffer[57]);
LCD1602_write_word("m");
LCD1602_write_com(0x80+0x40); //Set pointer
LCD1602_write_data(Display_GPGGA_Buffer[28]); //N or S
LCD1602_write_data(Display_GPGGA_Buffer[17]); //Latitude
LCD1602_write_data(Display_GPGGA_Buffer[18]); //Latitude
LCD1602_write_data(0xdf); //degrees
LCD1602_write_data(Display_GPGGA_Buffer[19]); //Latitude
LCD1602_write_data(Display_GPGGA_Buffer[20]); //Latitude
LCD1602_write_word("'"); //seconds
LCD1602_write_data(Display_GPGGA_Buffer[42]); //E or W
LCD1602_write_data(Display_GPGGA_Buffer[30]); //Longitude
LCD1602_write_data(Display_GPGGA_Buffer[31]);
LCD1602_write_data(Display_GPGGA_Buffer[32]);
LCD1602_write_data(0xdf);
LCD1602_write_data(Display_GPGGA_Buffer[33]);
LCD1602_write_data(Display_GPGGA_Buffer[34]);
LCD1602_write_word("'");
}
if(Flag_GPS_OK == 1 && RX_Buffer[4] == 'M' && RX_Buffer[52] == ',' && RX_Buffer[59] == ',') //Confirm whether the "GPRMC" frame data is received
{
for( i = 0; i < 68 ; i++)
{
Display_GPRMC_Buffer[i] = RX_Buffer[i];
}
Year_High = Display_GPRMC_Buffer[57];
Year_Low = Display_GPRMC_Buffer[58];
Month_High = Display_GPRMC_Buffer[55];
Month_Low = Display_GPRMC_Buffer[56];
Day_High = Display_GPRMC_Buffer[53];
Day_Low = Display_GPRMC_Buffer[54];
if(Flag_OV == 1) // Carry
{
UTCDate2LocalDate(); //Convert UTC date to Beijing time
}
Flag_Calc_GPRMC_OK = 1;
}
if(Page == 1 && Flag_Calc_GPRMC_OK == 1)
{
LED1 = ~LED1;
Flag_Calc_GPRMC_OK = 0;
LCD1602_write_com(0x80); //Set pointer
LCD1602_write_word("20");
LCD1602_write_data(Year_High);
LCD1602_write_data(Year_Low);
LCD1602_write_data('-');
LCD1602_write_data(Month_High);
LCD1602_write_data(Month_Low);
LCD1602_write_data('-');
LCD1602_write_data(Day_High);
LCD1602_write_data(Day_Low);
LCD1602_write_com(0x80+0x40); //Set pointer
LCD1602_write_word("Speed:"); //Display content
LCD1602_write_data(Display_GPRMC_Buffer[46]);
LCD1602_write_data(Display_GPRMC_Buffer[47]);
LCD1602_write_data(Display_GPRMC_Buffer[48]);
LCD1602_write_data(Display_GPRMC_Buffer[49]);
LCD1602_write_data(Display_GPRMC_Buffer[50]);
LCD1602_write_word("m/s");
}
}
}
//****************************************************
//Convert UTC date to local date
//****************************************************
void UTCDate2LocalDate(void)
{
Day = (Day_High - 0x30) * 10 + (Day_Low-0x30) + 1; //Day plus one
Month = (Month_High - 0x30) * 10 + (Month_Low - 0x30);
Year = 2000 + (Year_High - 0x30) * 10 + (Year_Low - 0x30);
MaxDay = GetMaxDay(Month,Year); //Get the maximum number of days in the month
if(Day > MaxDay) // overflow
{
Day = 1;
Month += 1;
if(Month > 12)
{
Year+=1;
}
}
Day_High = Day/10 + 0x30; //Convert date value to ASCII
Day_Low = Day%10 + 0x30;
Month_High = Month/10 + 0x30; //Convert month value to ASCII
Month_Low = Month%10 + 0x30;
Year_High = Year%100/10 + 0x30; //Convert year value to ASCII
Year_Low = Year%10 + 0x30;
}
//****************************************************
//Get the maximum value of the date in the month
//****************************************************
unsigned char GetMaxDay(unsigned char Month_Value,unsigned int Year_Value)
{
unsigned char iDays;
switch(Month_Value)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
iDays = 31;
}
break;
case 2:
{
// February is special. It is necessary to determine whether the month has 28 or 29 days based on whether it is a leap year.
iDays = IsLeapYear(Year_Value)?29:28;
}
break;
case 4:
case 6:
case 9:
case 11:
{
iDays = 30;
}
break;
default : break;
}
return(iDays);
}
//****************************************************
// Leap year detection
//****************************************************
bit IsLeapYear(unsigned int uiYear)
{
……………………
Previous article:Program for making a microcontroller tracking car
Next article:A complete design of a heart rate tester made with a single chip microcomputer and st188
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Data sharing: A brief review of the 2018 National Undergraduate Electronic Design Competition TI Cup and sharing of preparation experience
- STM32 assignment question
- LIS331DLH three-axis acceleration sensor package and code
- EEWORLD University - EOS and ESD on ADC
- NodeMcuEsp8266-L298N drives DC motor
- What is 5G IoT? Current applications of 5G IoT
- How to get started with developing a low-power Bluetooth using cc2650?
- [RVB2601 Creative Application Development] LVGL Horizontal Scrolling Display
- BQ4050 charging and discharging failure
- 12 details of PCB layout