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

📄 uart.lst

📁 TSL256源程序驱动!通过其IIC口采集环境光光强
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.15   UART                                                                  12/25/2008 21:36:25 PAGE 1   


C51 COMPILER V8.15, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN .\uart.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Inc\uart.c ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND PRINT(.\uart.lst) OBJE
                    -CT(.\uart.obj)

line level    source

   1          //**********************************************************
   2          //**                     串口通讯程序                     **
   3          //**          单片机: STC12C5410AD 主频: 24MHz          **
   4          //**              Jumping <2008.04.20>              **
   5          //**********************************************************
   6          
   7          //#include <REGx051.H>                                                          // AT89C4051头文件
   8          #include "../inc/STC12C5410AD.H"                                                                // AT89C4051头文件
   9          #include "def.h"                                                                        // 类型定义文件
  10          #include "config.h"                                                                     // 参数配置头文件
  11          #include "uart.h"                                                                       // uart通讯程序头文件
  12          #include "time0.h"
  13          // *** 全局变量定义 ***
  14          
  15          
  16          
  17          // *** 全局变量定义 ***
  18          
  19          uchar data uart_buff[16];                                                       // uart收发缓冲区(单队列)
  20          uchar data uart_dptr;                                                           // uart收发缓冲区读写指针
  21          
  22          uchar data uart_over;                                                           // uart超时计数器
  23          uchar data uart_flag;                                                           // uart帧接收标志
  24          uint  data uart_crc;                                                            // uart帧CRC校验
  25          
  26          uchar data uart_tlen;                                                           // uart发送数据长度
  27          
  28          
  29          
  30          // *** 函数声明 ***
  31          
  32          void uart_init (void);
  33          void uart_send (uint data_leng);
  34          uint calc_crc (uint crc_data, uchar chk_data);
  35          void delay_1ms (uchar count);
  36          void sss(void);
  37          
  38          // 串口中断程序
  39          
  40          void uart_ISR (void) interrupt 4
  41          {
  42   1              uchar ch;
  43   1              uint crc;
  44   1      
  45   1              if (RI==1)                                                                              // 接收处理
  46   1              {
  47   2                      RI = 0;                                                                         // 清接收标志
  48   2                      ch = SBUF;                                                                      // 取收到的数据
  49   2      
  50   2                      if (uart_over==0) uart_dptr = 0;                        // 超时, 重新开始接收数据
  51   2                      uart_over = 10;                                                         // 置超时时间初值: 10*10mS = 100mS
  52   2      
  53   2                      uart_buff[uart_dptr] = ch;                                      // 保存数据
  54   2                      uart_dptr++;                                                            // 缓冲区指针加1
C51 COMPILER V8.15   UART                                                                  12/25/2008 21:36:25 PAGE 2   

  55   2      
  56   2                      switch (uart_dptr)
  57   2                      {
  58   3                              case 1:                                                                 // 数据帧第1字节, 地址
  59   3                              {
  60   4                                      if (ch!=LOCL_ADDR) uart_dptr = 0;       // 第1字节不为locl_addr则丢弃
  61   4                                      break;                                                          // 退出case
  62   4                              }
  63   3      
  64   3                              case 2:                                                                 // 数据帧第2字节, 功能码
  65   3                              {
  66   4                                      if (ch!=0x03)                                           // 第2字节不为0x03则丢弃
  67   4                                      {
  68   5                                              uart_dptr = 0;                                  // 重新开始接收数据
  69   5      
  70   5                                              if (ch==LOCL_ADDR)                              // 该字节为数据帧第1字节
  71   5                                              {
  72   6                                                      uart_buff[uart_dptr] = ch;      // 保存数据
  73   6                                                      uart_dptr++;                            // 缓冲区指针加1
  74   6                                              }
  75   5                                      }
  76   4                                      break;                                                          // 退出case
  77   4                              }
  78   3      
  79   3                              case 3:                                                                 // 数据帧第3字节, 第一个寄存器的高位地址
  80   3                              {
  81   4                                      LED = 0;                                                        // 开LED
  82   4                                      break;                                                          // 退出case
  83   4                              }
  84   3      
  85   3                              case 4:                                                                 // 数据帧第4字节, 第一个寄存器的低位地址
  86   3                              {
  87   4                                      break;                                                          // 退出case
  88   4                              }
  89   3      
  90   3                              case 5:                                                                 // 数据帧第5字节, 寄存器的数量的高位
  91   3                              {
  92   4                                      break;                                                          // 退出case
  93   4                              }
  94   3      
  95   3                              case 6:                                                                 // 数据帧第6字节, 寄存器的数量的底位
  96   3                              {
  97   4                                      break;                                                          // 退出case
  98   4                              }
  99   3      
 100   3                              case 7:                                                                 // 数据帧第7字节, CRC校验高字节
 101   3                              {
 102   4                                      uart_crc = ch;                                          // crc低8位
 103   4                                      break;                                                          // 退出case
 104   4                              }
 105   3      
 106   3                              case 8:                                                                 // 数据帧第8字节, CRC校验低字节
 107   3                              {
 108   4                                      uart_crc = (ch << 8 ) | uart_crc;       // crc高8位
 109   4      
 110   4                                      crc = 0xffff;                                           // 置CRC初值
 111   4                                      for (ch=0; ch<6; ch++)                          // 循环计算CRC
 112   4                                      {
 113   5                                              crc = calc_crc(crc, uart_buff[ch]);     // 计算CRC
 114   5                                      }
 115   4      
 116   4                                      //jumping080509
C51 COMPILER V8.15   UART                                                                  12/25/2008 21:36:25 PAGE 3   

 117   4                                      if (uart_crc==crc)                                      // 如果是有效数据, 置接收标志
 118   4                                      {
 119   5                                              delay_1ms(2);                                   // 延时2mS
 120   5                                              link_cont=0;                        // 链接时间置零 当值大于500(5秒)pwm值将置为255
 121   5      
 122   5                                              uart_buff[0] = LOCL_ADDR;               // 1: 地址
 123   5                                              uart_buff[1] = 0x03;                    // 2: 功能码
 124   5                                              uart_buff[2] = 0x04;                    // 3: 字节数
 125   5                                              //curt_brit=9999;//
 126   5                                              uart_buff[3] = curt_brit/256;   // 4: 数据高字节
 127   5                                              uart_buff[4] = curt_brit%256;   // 5: 数据低字节
 128   5                                              uart_buff[5] = 0x00;                    // 6: 数据高字节
 129   5                                              uart_buff[6] = 0x00;                    // 7: 数据低字节
 130   5                                              uart_buff[7] = 0x00;                    // 8: CRC校验高位
 131   5                                              uart_buff[8] = 0x00;                    // 9: CRC校验底位
 132   5      
 133   5                                              uart_send(9);                                   // 发送应答帧
 134   5                                      }
 135   4      
 136   4                                      uart_dptr = 0;                                          // 重新开始接收数据
 137   4                                      LED = 1;                                                        // 关LED
 138   4                                      break;                                                          // 退出case
 139   4                              }
 140   3      
 141   3                              default:                                                                // 错误数据
 142   3                              {
 143   4                                      uart_dptr = 0;                                          // 重新开始接收数据
 144   4                                      break;                                                          // 退出case
 145   4                              }
 146   3                      }
 147   2              }
 148   1      
 149   1              if (TI==1)                                                                              // 发送处理
 150   1              {

⌨️ 快捷键说明

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