⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.lst

📁 此程序是GPS的解码程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   UART                                                                  05/20/2008 17:39:32 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN uart.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uart.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          
   2          #include "common.h"
   3          #include "uart.h"
   4          
   5          
   6          // 串口数据定义 
   7          
   8          //unsigned char UART_Buffer[UART_BUFFERSIZE];
   9          unsigned char UART_Buffer_Size = 0; 
  10          unsigned char UART_Input_First = 0;
  11          static unsigned char  tmp;
  12          
  13          // GPS数据接收定义
  14          
  15          unsigned char JD[10]={"00000.0000"};                    //经度
  16          unsigned char JD_a='*';                             //经度方向
  17          unsigned char WD[9]={"0000.0000"};                          //纬度
  18          unsigned char WD_a='*';                                 //纬度方向
  19          unsigned char time[6]={"000000"};                   //时间
  20          unsigned char date[6]={"000000"};                       //日期
  21          unsigned char speed[5];                             //速度
  22          unsigned char Height[6];                                //高度
  23          unsigned char angle[5];                             //方位角
  24          unsigned char use_sat[2]={"00"};                        //使用的卫星数
  25          unsigned char total_sat[2]={"00"};                  //天空中总卫星数
  26          
  27          //串口中断需要的变量
  28          unsigned char seg_count;                //逗号计数器
  29          unsigned char dot_count;                //小数点计数器
  30          unsigned char byte_count;               //位数计数器
  31          unsigned char cmd_number;               //命令类型
  32          unsigned char mode;                             //0:结束模式,1:命令模式,2:数据模式
  33          unsigned char buf_full;                 //1:整句接收完成,相应数
  34          unsigned char cmd[5];                   //命令类型存储数组
  35          
  36          //显示需要的变量
  37          unsigned char dsp_count;                //刷新次数计数器
  38          unsigned char time_count;
  39          
  40          unsigned char Height_num,a_num,s_num;
  41          
  42          void UART0_Init (void)
  43          {
  44   1         char SFRPAGE_SAVE;
  45   1      
  46   1         SFRPAGE_SAVE = SFRPAGE;             // Preserve SFRPAGE
  47   1      
  48   1         SFRPAGE = TMR2_PAGE;
  49   1      
  50   1         TMR2CN = 0x00;                      // Timer in 16-bit auto-reload up timer
  51   1                                             // mode
  52   1         TMR2CF = 0x08;                      // SYSCLK is time base; no output;
  53   1                                             // up count only
  54   1         RCAP2 = - ((long) SYSTEMCLOCK/BAUDRATE/16);
  55   1         TMR2 = RCAP2;
C51 COMPILER V8.02   UART                                                                  05/20/2008 17:39:32 PAGE 2   

  56   1         TR2= 1;                             // Start Timer2
  57   1      
  58   1         SFRPAGE = UART0_PAGE;
  59   1      
  60   1         SCON0 = 0x50;                       // 8-bit variable baud rate;
  61   1                                             // 9th bit ignored; RX enabled
  62   1                                             // clear all flags
  63   1         SSTA0 = 0x15;                       // Clear all flags; enable baud rate
  64   1                                             // doubler (not relevant for these
  65   1                                             // timers);
  66   1                                             // Use Timer2 as RX and TX baud rate
  67   1                                             // source;
  68   1         ES0 = 1;  
  69   1         IP |= 0x10;
  70   1      
  71   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFRPAGE
  72   1      }
  73          
  74          
  75          void UART0_Interrupt (void) interrupt 4
  76          {
  77   1         SFRPAGE = UART0_PAGE;
  78   1      
  79   1         if (RI0 == 1)
  80   1         {
  81   2            if( UART_Buffer_Size == 0)  {      // If new word is entered
  82   3               UART_Input_First = 0;    }
  83   2      
  84   2            RI0 = 0;                           // Clear interrupt flag
  85   2      
  86   2            tmp=SBUF0;            //将接收数据暂时保存
  87   2              switch(tmp){
  88   3                      case '$':
  89   3                              cmd_number=0;           //命令类型清空
  90   3                              mode=1;                         //接收命令模式
  91   3                              byte_count=0;           //接收位数清空
  92   3                              break;
  93   3                      case ',':
  94   3                              seg_count++;            //逗号计数加1
  95   3                              byte_count=0;
  96   3                              break;
  97   3                      case '*':
  98   3                              switch(cmd_number){
  99   4                                      case 1:
 100   4                                              buf_full|=0x01;
 101   4                                              break;
 102   4                                      case 2:
 103   4                                              buf_full|=0x02;
 104   4                                              break;
 105   4                                      case 3:
 106   4                                              buf_full|=0x04;
 107   4                                              break;
 108   4                                      case 4:
 109   4                                              buf_full|=0x08;
 110   4                                              break;
 111   4                              }
 112   3                              mode=0;
 113   3                              break;
 114   3                      default:
 115   3                              if(mode==1){
 116   4                                      //命令种类判断
 117   4                                      cmd[byte_count]=tmp;                    //接收字符放入类型缓存
C51 COMPILER V8.02   UART                                                                  05/20/2008 17:39:32 PAGE 3   

 118   4                                      if(byte_count>=4){                              //如果类型数据接收完毕,判断类型
 119   5                                              if(cmd[0]=='G'){
 120   6                                                      if(cmd[1]=='P'){
 121   7                                                              if(cmd[2]=='G'){
 122   8                                                                      if(cmd[3]=='G'){
 123   9                                                                              if(cmd[4]=='A'){
 124  10                                                                                      cmd_number=1;
 125  10                                                                                      mode=2;
 126  10                                                                                      seg_count=0;
 127  10                                                                                      byte_count=0;
 128  10                                                                                      Height_num=0;
 129  10                                                                              }
 130   9                                                                      }
 131   8                                                                      else if(cmd[3]=='S'){
 132   9                                                                              if(cmd[4]=='V'){
 133  10                                                                                      cmd_number=2;
 134  10                                                                                      mode=2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -