GPS_CHECKTIAMER serial port transceiver program

Publisher:忙中取乐Latest update time:2012-08-25 Source: 51heiKeywords:GPS Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
MCU serial port sending and receiving program, the following is about GPS_CHECKTIAMER, local application program

 

#define UART_R_LEN 60
#define UART_T_LEN 34

uchar idata trdata[UART_T_LEN]; //Define the serial port send buffer
uchar idata gpsdata[UART_R_LEN]; //Define the GPS data serial port receiving buffer

uchar *inlast_t = trdata; //Last put into the send buffer
uchar *outlast_t = trdata; //The last out from the send buffer
uchar *inlast_r = gpsdata; //The last entry into the receive buffer
uchar *outlast_r = gpsdata; //The last one taken from the receiving buffer
bit t_empty,t_full,r_empty,r_full; //Buffer status flag
bit new_time,t_finish; //Receiving completion flag and sending completion flag

void serail(void) interrupt 4
{
    if(TI) //If the send interrupt is set
 {
     TI = 0;
  if(!t_empty) //If the send buffer data is not sent out
  {
  
      SBUF = *outlast_t; //The last character out of the send buffer is sent to SBUF
   outlast_t++; //The last character pointer address is increased by 1
   t_full = 0; //The sending area status is not full
   if(outlast_t >= (trdata + UART_T_LEN)) //If the address of the last character sent exceeds
     outlast_t = trdata; //Address to the top and back to the bottom
   if(outlast_t == inlast_t) //If the address of the last character sent is the address of the last character sent
     t_empty = 1;
  }
  else t_finish = 1;
 }

 if(RI) //If the receive interrupt is set
 {
  RI = 0;
  if(~r_full) //If the receive buffer is not full
  {
   *inlast_r = SBUF; //The last character entering the receive buffer is sent to SBUF
   inlast_r++; //The last character address entering the receive buffer increases by 1
   r_empty = 0; //Receive buffer is not empty
   if(inlast_r >= (gpsdata + UART_R_LEN)) //If the address of the last received character exceeds
     inlast_r = gpsdata; //Address to the top and back to the bottom
   if(inlast_r == outlast_r)    
//If the address of the last character received is equal to the address of the last character taken from the receiving area
     r_full = 1; //The receiving area is full
  }
 }
}

void loadmsg(uchar *msg, int num) //Put the string into the send buffer and prepare to send
{
 int i;

 for(i=0; i= (trdata+UART_T_LEN))
    inlast_t = trdata; //Address to the top and back to the bottom
  if(inlast_t == outlast_t)
    t_full = 1; //Send buffer is full
  
 }

 if(t_finish)
 {
  TI = 1;
  t_finish = 0;
 }

}


uchar getbyte_r(void) //Get a byte from the receive buffer
{
 uchar c;
 while(r_empty); //When the receive buffer is waiting for reception
 ES = 0; //Disable serial interrupt
 c = *outlast_r; //The last data taken from the receiving buffer is assigned to C
 r_full = 0; //Receiving is not full
 outlast_r++; //The last data address taken from the receiving buffer increases by 1
 if(outlast_r >= (gpsdata + UART_R_LEN)) //If the address exceeds
   outlast_r = gpsdata; //Address back to original place
 if(outlast_r == inlast_r)    
//If the address of the last character received is equal to the address of the last character taken from the receiving area
   r_empty = 1; //The receive buffer is empty
 ES = 1; //Resume serial interrupt
 return c;
}

uchar r_state = 0;
uchar r_byte = 0;
uchar gps_chksum= 0;

void r_string(void) // Receive string
{
 uint *ptr;
  
 uchar temp;
 uchar tp[7];   
//Define the time stamp receiving area. The stored time stamp data is the time stamp that has not been converted in the receiving buffer. It is used as the transfer storage of the global time stamp

 while(!r_empty && !new_time) //If the receive buffer is not empty and the receive is not completed
 {
  temp = getbyte_r(); //Each while loop takes in one byte of received data
  switch(r_state)      
//If the data sequentially taken in conforms to the header "@@Hb", r_state position 4, enter the time stamp and GPS status byte
  {
   case 0:
    if(temp == 0x40) //@
      r_state = 1;
    break;
   case 1:
    if(temp == 0x40) //@  
    {
     r_state = 2;
     gps_chksum = 0;
    }
    else r_state = 0;
       break;
   case 2:
    if(temp == 0x48) //H
    {
                    r_state = 3;
     gps_chksum = gps_chksum^temp;
    }
    else r_state = 0;
    break;
   case 3:
    if(temp == 0x62) //b
    {
                    r_state = 4;
     r_byte = 0;
     gps_chksum = gps_chksum^temp;
    }
    else r_state = 0;
    break;
   case 4:
    if(r_byte == 47)
      { if(gps_chksum == temp)   
//After completing the useful data collection, after data conversion, the standard characters are stored in the global time stamp buffer
          {
        ptr = (uint*)(tp+2);    
                    //Send the converted data to the time stamp buffer
              gps_dt[0] = (*ptr)%100; //year
                 gps_dt[1] = tp[0]; //month
                 gps_dt[2] = tp[1]; //day
                 gps_dt[3] = tp[4]; //time
                 gps_dt[4] = tp[5]; // points
                 gps_dt[5] = tp[6]; // seconds
  
        new_time = 1;  
        }
     r_state = 0; //Reset the data used for judgment to zero so that the data can be retrieved next time
      }
    else
      {
     gps_chksum = gps_chksum^temp;

     if(r_byte <7)
          tp[r_byte] = temp;
     else if(r_byte == 38)
      gps_state = temp;

        r_byte++;
      }
    break;
      default:
       break;
  }

 }
}
Keywords:GPS Reference address:GPS_CHECKTIAMER serial port transceiver program

Previous article:The magic of pointers in C language
Next article:MCU detects short and continuous keystrokes C program

Recommended ReadingLatest update time:2024-11-17 01:48

Testing GPS Receivers Using Real Data
  Historically, GPS receiver designers have combined simulation and drive testing to determine receiver performance in complex environments. While GPS signal simulation provides a repeatable signal source, simulators cannot reproduce the complex multipath signal distortions common in the real world. In addition, drive
[Test Measurement]
Testing GPS Receivers Using Real Data
Key points for choosing GPS navigation products
With the development of social science and technology and economy, GPS navigation products have gradually become a must-have electronic product for private car owners. However, as a high-tech product that has just emerged in the past two years, many car owners not only do not know how to choose and buy navigation pr
[Analog Electronics]
GPS Receiver Test
Overview From the navigation operation of Boeing 747 passenger aircraft, the GPS navigation system used by car drivers every day, to the treasure hunter who wants to find the treasure hidden somewhere deep in the forest, GPS technology has been rapidly integrated into many applications. While innovative tec
[Test Measurement]
GPS Receiver Test
A Brief Analysis of Car GPS Navigation Positioning and Tracking Technology
Looking at the development of GPS navigation technology in the domestic market, it is not difficult to find that the coexistence trend of wireless technologies used in automobiles brings infinite possibilities, and also gives us unlimited imagination space. Specifically, PND is developing towards incorporating multi
[Automotive Electronics]
Design of GPS intelligent station announcement system for buses
     In recent years, with the rapid development of urban public transportation, the way of bus stop announcements in China has been greatly improved, from the traditional method of conductors announcing stops by shouting to drivers announcing stops manually using a station announcer.   Although manual station annou
[Microcontroller]
Design of GPS intelligent station announcement system for buses
Design and implementation of positioning function of embedded logistics information terminal
introduction Positioning technology is an important information foundation for logistics informatization and the main information basis for implementing logistics informatization control. The selection of logistics positioning solutions and technologies has an important impact on improving the efficiency of
[Microcontroller]
Design and implementation of GPS/GPRS vehicle monitoring terminal
In recent years, with the popularization of automobiles and the construction of roads, economic exchanges between cities have become more frequent, and the areas of activities have become larger and larger, resulting in serious problems such as traffic congestion, increased traffic accidents, and increased exhaust e
[Microcontroller]
Design and implementation of GPS/GPRS vehicle monitoring terminal
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号