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

📄 pca_9555.lst

📁 别人的C51菜单程序
💻 LST
字号:
C51 COMPILER V8.08   PCA_9555                                                              06/30/2007 15:23:46 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE PCA_9555
OBJECT MODULE PLACED IN PCA_9555.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE PCA_9555.c LARGE OPTIMIZE(9,SPEED) DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include "common.h"
   4          
   5          
   6          
   7          #define WriteDeviceAddress_9555         0x40
   8          #define ReadDeviceAddress_9555          0x41
   9          #define Commond_input0          0x00
  10          #define Commond_input1          0x01
  11          #define Commond_output0         0x02
  12          #define Commond_output1         0x03
  13          #define Commond_polarity0       0x04
  14          #define Commond_polarity1       0x05
  15          #define Commond_config0         0x06
  16          #define Commond_config1         0x07
  17          sbit PCA9555_SCL=P1^0;
  18          sbit PCA9555_SDA=P1^1;  
  19          /*void delay_pca9555(void)
  20          {
  21                  uchar i;
  22                  for(i=0;i<20;i++);
  23          } */
  24          
  25          void start_9555(void)
  26          {
  27   1              PCA9555_SCL=0;
  28   1              PCA9555_SDA=1;
  29   1              nop();
  30   1              nop();
  31   1              nop();
  32   1              nop();
  33   1              nop();
  34   1              nop();
  35   1      
  36   1              PCA9555_SCL=1;
  37   1              nop();
  38   1              nop();
  39   1              nop();
  40   1              nop();
  41   1              nop();
  42   1      
  43   1              PCA9555_SDA=0;
  44   1              nop();
  45   1              nop();
  46   1              nop();
  47   1              nop();
  48   1              nop();
  49   1      }
  50          
  51          void stop_9555()
  52          {
  53   1              PCA9555_SCL=0;
  54   1              PCA9555_SDA=0;
  55   1              nop();
C51 COMPILER V8.08   PCA_9555                                                              06/30/2007 15:23:46 PAGE 2   

  56   1              nop();
  57   1              nop();
  58   1              nop();
  59   1              nop();
  60   1      
  61   1              PCA9555_SCL=1;
  62   1              nop();
  63   1              nop();
  64   1              nop();
  65   1              nop();
  66   1              nop();
  67   1      
  68   1              
  69   1              PCA9555_SDA=1;
  70   1              nop();
  71   1              nop();
  72   1              nop();  
  73   1              nop();
  74   1              nop();
  75   1      }       
  76          
  77          //发应答信号
  78          void ack(void)
  79          {
  80   1              PCA9555_SCL=0;
  81   1              nop();
  82   1              nop();
  83   1              PCA9555_SDA=0;
  84   1              PCA9555_SCL=1;
  85   1              nop();
  86   1              nop();
  87   1              
  88   1      }
  89          //发非应答信号
  90          void no_ack(void)
  91          {
  92   1              PCA9555_SCL=0;
  93   1              nop();
  94   1              nop();
  95   1              PCA9555_SDA=1;
  96   1              PCA9555_SCL=1;
  97   1              nop();
  98   1              nop();
  99   1      }
 100          //写字节
 101          bit write8bit(uchar input)
 102          {
 103   1              uchar i;
 104   1              for(i=0;i<8;i++)
 105   1              {
 106   2                      PCA9555_SCL=0;
 107   2                      input=input<<1;
 108   2                      PCA9555_SDA=CY;
 109   2                      nop();
 110   2                      nop();
 111   2                      PCA9555_SCL=1;
 112   2                      nop();
 113   2              } 
 114   1              
 115   1              PCA9555_SCL=0;                          //read ack
 116   1              nop();
 117   1              nop();
C51 COMPILER V8.08   PCA_9555                                                              06/30/2007 15:23:46 PAGE 3   

 118   1              nop();
 119   1              nop(); 
 120   1              PCA9555_SCL=1;
 121   1              nop();
 122   1      
 123   1              CY=PCA9555_SDA;
 124   1              if(CY)
 125   1              return 0;
 126   1              else 
 127   1              return 1;
 128   1      
 129   1      }
 130          //读字节
 131          uchar pca9555_read8bit(void) 
 132          {
 133   1              uchar data i,pcadata=0;
 134   1              for(i=0;i<8;i++)
 135   1              {
 136   2                      PCA9555_SCL=0;
 137   2                      nop();
 138   2                      pcadata=(pcadata<<1)|PCA9555_SDA;
 139   2                      PCA9555_SCL=1;
 140   2              }
 141   1      
 142   1              return pcadata;
 143   1      }
 144          //写pca9555输出寄存器
 145          void writeoutput(uchar input1,uchar input2)
 146          {
 147   1              start_9555();
 148   1              write8bit(WriteDeviceAddress_9555);
 149   1              write8bit(Commond_output0);
 150   1              write8bit(input1);
 151   1              write8bit(input2);
 152   1              stop_9555();
 153   1      }
 154          //写pca9555配置寄存器
 155          void writeconfig(uchar input1,uchar input2)
 156          {
 157   1              start_9555();
 158   1              write8bit(WriteDeviceAddress_9555);
 159   1              write8bit(Commond_config0);
 160   1              write8bit(input1);
 161   1              write8bit(input2);
 162   1              stop_9555();
 163   1      }
 164          
 165          void readregister(uchar data *data_pca9555)             //
 166          {
 167   1              start_9555();
 168   1              write8bit(WriteDeviceAddress_9555);
 169   1              write8bit(Commond_input0);
 170   1              start_9555();
 171   1              write8bit(ReadDeviceAddress_9555);
 172   1              data_pca9555[0]=pca9555_read8bit();
 173   1              ack();
 174   1              //delay_pca9555();
 175   1              data_pca9555[1]=pca9555_read8bit();
 176   1              no_ack();
 177   1              stop_9555();
 178   1      
 179   1      }
C51 COMPILER V8.08   PCA_9555                                                              06/30/2007 15:23:46 PAGE 4   

 180          //
 181          void pca9555_init(void)
 182          {
 183   1               writeconfig(0xff,0x00);//I/O 0为输出,I/O 1为输入
 184   1               writeoutput(0x00,0xfe);//
 185   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    237    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       2
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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