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

📄 func_shi.lst

📁 台湾VX1818 TFT驱动模拟屏的源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   FUNC_SHI                                                              12/31/2004 22:02:01 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE FUNC_SHI
OBJECT MODULE PLACED IN func_shi.OBJ
COMPILER INVOKED BY: z:\Keil\C51\BIN\C51.EXE func_shi.C BROWSE DEBUG OBJECTEXTEND

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          
  27          
  28          extern void delay_nop();
  29          extern void stop_con();
  30          extern void start_con();
  31          extern void nack_con();
  32          extern void ack_con();
  33          extern bit send_con(char);
  34          extern char receive_con();
  35          
  36          sbit sda = P0^0;
  37          sbit scl = P0^1;
  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:
  55                  1.Program will read "num_data" datum from the "address" of "device"
C51 COMPILER V7.50   FUNC_SHI                                                              12/31/2004 22:02:01 PAGE 2   

  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          stop_con();                                 // Master send Stop command
  69   2          delay_nop();
  70   2          start_con();                                // Master send Start command
  71   2          ack = send_con(device++);           // Send the device number and Set the R/W bit
  72   2          if (!ack)
  73   2          {
  74   3            ack = send_con(address);  // Send the address of reg
  75   3            if (!ack)
  76   3            {
  77   4              com = 1;                                // Motion is complete
  78   4            }
  79   3          }
  80   2        }
  81   1        delay_nop();
  82   1      
  83   1        // Ready for receive data
  84   1        com = 0;
  85   1        while (!com)
  86   1        {
  87   2         buf_data_temp = buf_data;
  88   2      
  89   2         stop_con();                                                          // Master send Stop command
  90   2         delay_nop();
  91   2         start_con();                                                         // Master send Start command
  92   2         ack = send_con(device);                              // Send the device number and Set the R/W bit
  93   2         if (!ack)
  94   2         {
  95   3          for (count = 0;count <= num_data;count++)
  96   3          {
  97   4           *buf_data_temp = receive_con();                    // Save received data to buf_data
  98   4               buf_data_temp++;                                                       // Address index increase
  99   4           if (count != num_data)                             // Check whether the data is the last
 100   4           {
 101   5            ack_con();
 102   5           }
 103   4           else
 104   4           {
 105   5            nack_con();
 106   5            com = 0;
 107   5            goto Com_Received;
 108   5           }
 109   4          }
 110   3        }
 111   2       }
 112   1      Com_Received:
 113   1        delay_nop();
 114   1        stop_con();
 115   1        delay_nop();
 116   1      }
 117          
C51 COMPILER V7.50   FUNC_SHI                                                              12/31/2004 22:02:01 PAGE 3   

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

⌨️ 快捷键说明

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