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

📄 func_shi.lst

📁 小车上用的电脑锁方案(射频卡当钥匙):包括原理图
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   FUNC_SHI                                                              05/31/2005 22:13:56 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE FUNC_SHI
OBJECT MODULE PLACED IN func_shi.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe func_shi.C DB OE SMALL ROM(LARGE)

line level    source

   1          
   2          /*********************************************************************
   3            SHI Communication Function Version 1.2 (Copyright(c) VXIS Inc. 2002)
   4            v1.0
   5            Data:2002.08.02
   6            by P.J. Yang
   7            v1.1
   8            Data:2002.08.07
   9            by P.J. Yang
  10            v1.2
  11            Data:2002.08.14
  12            by P.J. Yang
  13            Modify:1. Modify DelayXms Function's input mode. char => unsigned char
  14                   2. Change shi_sub_write Function's variable from "buf_data_temp"
  15                      to "buf_data_temp1".
  16            v1.3
  17            Data:2002.09.12
  18            by P.J. Yang
  19            Modify:1. Remove delay to speed SHI's SCL clock.
  20                      SHI Frequency = 53kHz
  21          *********************************************************************/
  22          
  23          #include <intrins.h>
  24          #include <stdio.h>
  25          #include <reg51.h>
  26          #include "MCUIO.H"
*** ERROR C202 IN LINE 8 OF MCUIO.H: 'P4': undefined identifier
  27          
  28          
  29          extern void delay_nop();
  30          extern void stop_con();
  31          extern void start_con();
  32          extern void nack_con();
  33          extern void ack_con();
  34          extern bit send_con(char);
  35          extern char receive_con();
  36          
  37          
  38          char bytedata = 0;              // 8 bits buffer for both send and receive
  39          bit ack;                        // Ack = 0 => Acknowledge
  40                                          // Ack = 1 => No Acknowledge
  41          
  42          /*********************************************************************
  43             Readdata Function
  44          
  45          Input Factor:
  46                  device   => 7 bits , Device number (LSB must be zero)
  47                  address  => 8 bits , Reg address
  48                  num_data => 8 bits , (Number of received data)-1
  49                  buf_data => 8 bits , A index point to receive data buffer
  50          
  51          Output Factor:
  52                  None
  53          
  54          Motion:
C51 COMPILER V7.20   FUNC_SHI                                                              05/31/2005 22:13:56 PAGE 2   

  55                  1.Program will read "num_data" datum from the "address" of "device"
  56                    to the register of "buf_data" address.
  57          *********************************************************************/
  58          void shi_sub_read(char device,char address,char num_data,char *buf_data)
  59          {
  60   1        unsigned char count = 0;
  61   1      //  char temp = num_data;
  62   1        char *buf_data_temp;
  63   1        bit com = 0;                                  // A flag to indicate whether the read motion is complete
  64   1                                                                      // com = 0 => Not complete
  65   1                                                                      // com = 1 => Complete
  66   1        while (!com)
  67   1        {
  68   2          start_con();                                // Master send Start command
  69   2          ack = send_con(device++);           // Send the device number and Set the R/W bit
  70   2          if (!ack)
  71   2          {
  72   3            ack = send_con(address);  // Send the address of reg
  73   3            if (!ack)
  74   3            {
  75   4              com = 1;                                // Motion is complete
  76   4            }
  77   3          }
  78   2        }
  79   1        delay_nop();
  80   1      
  81   1        // Ready for receive data
  82   1        com = 0;
  83   1        while (!com)
  84   1        {
  85   2         buf_data_temp = buf_data;
  86   2      
  87   2         stop_con();                                                          // Master send Stop command
  88   2         delay_nop();
  89   2         start_con();                                                         // Master send Start command
  90   2         ack = send_con(device);                              // Send the device number and Set the R/W bit
  91   2         if (!ack)
  92   2         {
  93   3          for (count = 0;count <= num_data;count++)
  94   3          {
  95   4           *buf_data_temp = receive_con();                    // Save received data to buf_data
  96   4               buf_data_temp++;                                                       // Address index increase
  97   4           if (count != num_data)                             // Check whether the data is the last
  98   4           {
  99   5            ack_con();
 100   5           }
 101   4           else
 102   4           {
 103   5            nack_con();
 104   5            com = 0;
 105   5            goto Com_Received;
 106   5           }
 107   4          }
 108   3        }
 109   2       }
 110   1      Com_Received:
 111   1        delay_nop();
 112   1        stop_con();
 113   1        delay_nop();
 114   1      }
 115          
 116          /*********************************************************************
C51 COMPILER V7.20   FUNC_SHI                                                              05/31/2005 22:13:56 PAGE 3   

 117              Writedata Function
 118          
 119          Input Factor:
 120                  device   => 7 bits , Device number (LSB must be zero)
 121                  address  => 8 bits , Reg address
 122                  num_data => 8 bits , (Number of transmitted data) - 1
 123                  buf_data => 8 bits , A index to point transmit data buffer
 124          
 125          Output Factor:
 126                  None
 127          
 128          Motion:
 129                  1.Program will write "num_data" datum from the register of "buf_data" address
 130                    to the "address" of "device".
 131          *********************************************************************/
 132          void shi_sub_write(char device,char address,unsigned char num_data,char *buf_data)
 133          {
 134   1        bit com = 0;
 135   1        unsigned char count = 0;
 136   1      //  unsigned char temp = num_data;
 137   1        char *buf_data_temp1;
 138   1      
 139   1        while (!com)
 140   1        {
 141   2          buf_data_temp1 = buf_data;
 142   2          start_con();                                                        // Master send Start command
 143   2          ack = send_con(device);                                     // Send the device number and Set the R/W bit
 144   2          if (!ack)
 145   2          {
 146   3            ack = send_con(address);                          // Send the address of reg
 147   3            for (count=0;count <= num_data;count++)
 148   3            {
 149   4              if (!ack)
 150   4              {
 151   5                ack = send_con(*buf_data_temp1);              // Send the data pointed the buf_data index
 152   5      
 153   5                    buf_data_temp1++;                                         // Address index increase
 154   5                if (count == num_data && !ack)
 155   5                {
 156   6                  com = 1;
 157   6                  break;
 158   6                }
 159   5              }
 160   4              else
 161   4              {
 162   5                break;
 163   5              }
 164   4            }
 165   3          }
 166   2        }
 167   1        delay_nop();
 168   1        stop_con();                                                           // Master send Stop command
 169   1        delay_nop();
 170   1      }
 171          
 172          
 173          /*********************************************************************
 174              Receivebyte Function
 175          *********************************************************************/
 176          char receive_con()
 177          {
 178   1        char count = 0;
C51 COMPILER V7.20   FUNC_SHI                                                              05/31/2005 22:13:56 PAGE 4   

 179   1      
 180   1        for (count=0;count<8;count++)

⌨️ 快捷键说明

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