// Author: antlu
#include#define DataPort P0 // display LED segment #define DrivePort P2 //display LED digit //sbit Gok_LED =P1^2; //Receive "$GPRMC," send LED bit disp_flag; bit rec; // receive rs232 OK_flag void DelayUs2x(unsigned char t);//us delay function declaration void DelayMs(unsigned char t); //ms?Delay? void Display(unsigned char n,unsigned char Num); // Display the seven-segment display unsigned char code segment[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// VFD unsigned char code grid[4]={ 0x01,0x02,0x04,0x08 }; // 10H H 10mm, Bit code 3>>minutes, Bit code 2>>10minutes, Bit code 1>>hours, Bit code 0>>10hours, unsigned char TempData[4]; //, store the segment data in the buffer to be displayed, and send it to the display using a table-like mapping method. TempData[ ] is where the 7-segment data to be displayed is placed unsigned char CLCK[6]; //void Display(char n,char Num); unsigned char count; void Display_Data_Operation(void) //Using time, minutes and seconds as the common language, convert the numbers into 7-segment display { TempData[3]= segment[CLCK[0]];//? // if (CLCK[2]==0) // TempData[3]=0; TempData[2]= segment[CLCK[1]];// TempData[1]= segment[CLCK[2]]; //segment TempData[0]= segment[CLCK[3]];// //Display(0,4); } //------------------------------------------------ -------------------------- void Display(unsigned char n,unsigned char Num) // Display the seven-segment display { unsigned char i; n=0; //It is no longer useful, but it is still set to 0 due to the previous programming. for(i=0;i { DataPort = TempData; // DrivePort = grid; DelayMs(5); //0908 update Change 20 to 10 due to flashing >>5>>2 } } void DelayUs2x(unsigned char t) { while(--t); } void DelayMs(unsigned char t) { while(t--) { //About 1mS delay DelayUs2x(245); DelayUs2x(245); } } ///////////////FROM GPS /////////////////////////////////// /////////////////// unsigned char Gok; // "$GPRMC," confirmation completed unsigned char REV_DATA; //temporary variable for storing RS232 buffer void Init_Timer0(void); //Timer initialization //----- FROM GPS PROG ----- void Init_Timer0(void) { TMOD |= 0x01; //Use mode 1, 16-bit timer, use the "|" symbol to avoid being affected when using multiple timers. EA=1; //? Hit? ET0=1; //Timer is on TR0=1; //Timer is on } void Timer0_isr(void) interrupt 1 { // static unsigned int count; TH0=(65536-2010)/256; //Reset value 2ms TL0=(65536-2010)%6; count++; if (count==10) { count=0; disp_flag=1; } } void UART_Init(void) { SCON = 0x50; // SCON: Mode 1, 8-bit UART, receive enabled TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit heavy? TH1 = 0xFA; // TH1: reset to 4800 11.0592MHz TR1 = 1; // TR1: timer 1 hit? EA = 1; // Hit? ES = 1; //Open the serial port? } void UART_SER (void) interrupt 4 //from serial port clock 1602 program { if(RI) //Judge whether it is receiving { RI=0; //? Clear the flag REV_DATA = SBUF; //Enter the value of rec=1; //rec_led=1; } if(TI) //If it is a send flag, clear it TI=0; } unsigned char GPRMC_K(void)//Compare $GPRMC { unsigned char TT; // conversion while(rec==0); if(rec==1) if(REV_DATA == 'G') //Compare all the way to the same "GPRMC," rec=0; else return 0; while(rec==0); if(rec==1) if(REV_DATA == 'P') rec=0; while(rec==0); if(rec==1) if(REV_DATA == 'R') //Compare all the way to the same "GPRMC," rec=0; else return 0; while(rec==0); if(rec==1) if(REV_DATA == 'M') //Compare all the way to the same "GPRMC," rec=0; while(rec==0); if(rec==1) if(REV_DATA == 'C') //Compare all the way to the same "GPRMC," rec=0; while(rec==0); if(rec==1) if(REV_DATA == ',') //Compare all the way and all must be the same "GPRMC," rec=0; else return 0; while(rec==0); if(rec==1) CLCK[0]=REV_DATA-0x30;//10hr rec=0; while(rec==0); if(rec==1) CLCK[1]=REV_DATA-0x30;//1hr rec=0; while(rec==0); if(rec==1) CLCK[2]=REV_DATA-0x30;//10min rec=0; while(rec==0); if(rec==1) CLCK[3]=REV_DATA-0x30;//1min rec=0; while(rec==0); if(rec==1) CLCK[4]=REV_DATA-0x30;//10sec rec=0; while(rec==0); if(rec==1) CLCK[5]=REV_DATA-0x30;//sec TT=CLCK[0]*10+CLCK[1]+8; if(TT>23) TT-=24; CLCK[0]=TT/10; CLCK[1]=TT; return 1; } void Get_Gps(void) { if(rec==1) { rec=0; //Clear the credit flag if(REV_DATA == '$') { Gok=GPRMC_K(); //Confirm receipt of "GPRMC," character } } } // --------- GPS MAIN PROGRAM ------------- void main(void) { Init_Timer0(); UART_Init(); while(1) { Get_Gps(); if(Gok==1) { Display_Data_Operation (); //Convert relevant values to display } if(disp_flag==1) { disp_flag=0; Display(0,4); } Display(0,4); } }
Previous article:51 MCU timer/counter improvement
Next article:Ultrasonic distance measurement 51 single chip microcomputer 12864 LCD display
Recommended ReadingLatest update time:2024-11-16 15:29
- Popular Resources
- Popular amplifiers
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
- Join the thread and have a chat: If I give you a motor board, what would you want to do?
- 【China Academy of Electronics Science】Recruitment of embedded/algorithm engineers
- Create a healthy life and achieve powerful tools
- Infineon XMC4800 Relax EtherCAT Kit Review Summary
- Analog Discovery 2 Review (5) Acquisition System Hardware Analysis
- GD32 Competition - Motor Control - Hardware Design
- Guo Tianxiang's New Concept 51 MCU C language tutorial. Getting started, improving, and developing
- C6678: How does the malloc function do byte alignment
- Detailed explanation of ADC of MSP430 microcontroller
- Realization of various wavelet transforms based on FPGA