GPS clock 51 single chip microcomputer program

Publisher:GoldenEclipseLatest update time:2015-01-14 Keywords:MCU  Clock  GPS Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I have collected the GPS clock program I saw on the Internet for reference by electronics enthusiasts. The GPS clock has very simple hardware and the program is not too complicated. It does not require buttons or DS1302 IC. It only requires a GPS module. The advantage is that it does not require time adjustment. As long as there is a satellite signal, the time can be checked.

 

// 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);
    }
}
Keywords:MCU  Clock  GPS Reference address:GPS clock 51 single chip microcomputer program

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

Research on PLC Based on AT89C55 Single Chip Microcomputer
With the rapid development of higher vocational education, the introduction of PLC technology into higher vocational education and as a more important course has reached a consensus in higher vocational education, which is an important measure for the modernization of curriculum construction. After studying the AT89
[Microcontroller]
Research on PLC Based on AT89C55 Single Chip Microcomputer
Simulation and Program of Stepper Motor Controlled by STC89C52RC MCU
This single chip microcomputer is STC89C52RC, this program is applied to step motor--28BYJ, a small stepper motor, with a power supply voltage of DC5V. It can be directly connected to the single chip microcomputer and driven by the UL2003 driver chip. The digital tube is a common cathode interface, which controls th
[Microcontroller]
Simulation and Program of Stepper Motor Controlled by STC89C52RC MCU
A Brief Discussion on the Application Program Architecture of Single Chip Microcomputer
              Everyone is familiar with MCU programs, but not many people actually use or consider architecture. With the increasing number of program development, I think architecture is very necessary. I posted a thread not long ago to discuss " How to structure your MCU program " with everyone, and found that not ma
[Microcontroller]
Full tutorial on developing an optical fingerprint recognition module (FPM10A) based on the STM32 microcontroller
1. Platform First of all, I used the STM32 development board MINI board The Taobao website for the optical fingerprint recognition module (FPM10A) is: http://item.taobao.com/item.htm?id=5380075198 2. Purchase a fingerprint module and you will get three pieces of information 1.Brief instructions 2.Functio
[Microcontroller]
Full tutorial on developing an optical fingerprint recognition module (FPM10A) based on the STM32 microcontroller
How to encrypt MSP430 microcontroller?
1. Why and how to encrypt? When your product is launched on the market, your competitors will start to target it. If the hardware of your product is easily imitated and the MSP430 microcontroller you use is not encrypted, then your hard-earned success can easily become your competitor's product. Although the JTAG debu
[Microcontroller]
Implementation Analysis of 51 Microcontroller IIC Bus
The IIC bus (inter integrated circuit bus) is a high-performance inter-chip serial synchronous transmission bus invented by Philips. Unlike the SPI and Microwire interfaces, it only requires two signal lines - the serial data line SDA and the serial clock Line SCL realizes duplex synchronous data transmission, which c
[Microcontroller]
Implementation Analysis of 51 Microcontroller IIC Bus
ARM7 MCU programming example, ARM7 input/output port GPIO programming tutorial
  1. Input/output port GPIO programming   1--(01), 1-digit digital tube static display (realized by 74HC595)   1. Pin connection module   First, let me introduce the relevant pins of LPC2106~~   Features: Independent pin configuration is possible   Application: The purpose of the pin connection module is to configur
[Microcontroller]
ARM7 MCU programming example, ARM7 input/output port GPIO programming tutorial
Design and Analysis of Single Chip Microcomputer Power Supply Module
introduction Special monolithic Switching power supply There are two design schemes: the first is to use a general monolithic switching power supply integrated circuit (such as TOPSwitch-Ⅱ, TOPSwitch-FX, TOPSwitch-GX series), and then add a voltage control loop, current control loop and other
[Power Management]
Design and Analysis of Single Chip Microcomputer Power Supply Module
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号