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

📄 auxio.lst

📁 The code is for Auxiliary IO module which supports 16 inputs and 16 outputs and Modbus protocol
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 1   


C51 COMPILER V6.21, COMPILATION OF MODULE AUXIO
OBJECT MODULE PLACED IN Auxio.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Auxio.C BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include<intrins.h>
   2          #include <string.h>
   3          #include "REG52.H"
   4          
   5          #define DATA_PORT P0   
   6          #define LEN             P2_0
   7          #define BEN             P2_1
   8          #define DIR             P2_2
   9          #define HBIT    P2_3
  10          // To read DIP switch
  11          #define ID1             P1_0
  12          #define ID2             P1_1
  13          #define ID3             P1_2
  14          #define ID4             P1_3
  15          
  16          
  17          #define CBYTE ((unsigned char volatile code *)0)
  18          #define DBYTE ((unsigned char volatile idata *) 0)
  19            
  20          idata  char rxbuff[14];         //14
  21          idata  char txbuff[12];         //11
  22          
  23          
  24          
  25          idata unsigned char regbuff[4];
  26          //idata unsigned char regbitbuff;       
  27          
  28          
  29          
  30          
  31          #define ST_RD_03 0x0
  32          #define EN_RD_03 0x3 
  33          #define FN03_SUP 0x01
  34          
  35          #define ST_RD_04 0x0
  36          #define EN_RD_04 0x3
  37          #define FN04_SUP 0x01
  38          
  39          #define ST_WR_16 0x0 
  40          #define EN_WR_16 0x3
  41          #define FN16_SUP 0x01
  42          
  43          
  44          //#define ST_WR_15 0x0 
  45          //#define EN_WR_15 0x08
  46          //#define FN15_SUP 0x00
  47          
  48          #define EOFTM        0x05
  49          
  50          code unsigned char orl_data[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  51          code unsigned char anl_data[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
  52          //--------------------------------------------------------------
  53          //BITS
  54          //-------------------------------------------------------------
  55          //Com1 Related
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 2   

  56          idata bit com1_rec,com1_eof,com1_485dlystart,com1_485dlyend;
  57          
  58          //General
  59          idata bit ws,flag,dummy;
  60          idata bit valid_ok,flg_read,flg_analog;
  61          idata bit fun_sup,flg_single,flg_wrongfn,fun_support;
  62          
  63          
  64          //Characters
  65          //Com1
  66          idata unsigned char com1_txchar,com1_rxchar,com1_rxcnt,com1_txcnt,com1_eofcnt,com1_eoftm;
  67          idata unsigned char com1_offset,com1_dirdlycnt,com1_dirdlytm;
  68          
  69          //General Modbus
  70          idata unsigned char mod_fn,exc_code,crch,crcl;
  71          idata unsigned char mod_txlen,mod_txcnt,rx_dbcnt;  // can be removed
  72          idata unsigned char mod_srcaddr,mod_destaddr;
  73          idata unsigned char start_addr,end_addr,rec_addr,rec_length,addr_offset;
  74          idata unsigned int result,poly=40961;
  75          idata unsigned char Hbitcnt;
  76          
  77          //idata unsigned char remainder;
  78          
  79          //ModDrv1
  80          idata volatile unsigned char mod1_state,mod1_devid;
  81          //
  82          idata unsigned int indata;
  83          idata bit ndata =0 ; // new data
  84          //idata char decnt =0;
  85          
  86          void init(void);
  87          void ModSlave1(void);
  88          void validate(unsigned char,unsigned char);
  89          void read_response(unsigned char,unsigned char,unsigned char);
  90          void write_response(unsigned char,unsigned char);
  91          void store_data(unsigned char,unsigned char,unsigned char);
  92          void store16(unsigned char,unsigned char,unsigned char);
  93          void com1_txmode(void);
  94          void com1_tx(void);
  95          void com1_rxmode(void);      
  96          void cal_crc(unsigned char);
  97          void read3_4(unsigned char,unsigned char,unsigned char);
  98          void dly(unsigned int);
  99          void TransmitChar(unsigned char );
 100          void Output(unsigned char out);
 101          void Input(void);
 102          /******************************************************************************/
 103          /*                INTERRUPT0 interrupt service function                          */
 104          /******************************************************************************/
 105          /******************************************************************************/
 106          /*                Timer 0 interrupt service function                          */
 107          /*                executes each 250us @ 12 MHz Crystal Clock                  */
 108          /******************************************************************************/
 109          void timer0 (void) interrupt 1 using 1{   /* Int Vector at 000BH, Reg Bank 1 */
 110   1      //  static volatile char i=0;
 111   1      //  P1_5 = ~P1_5;                                                                       //power led
 112   1        Hbitcnt ++;
 113   1        if (Hbitcnt == 250)
 114   1        {
 115   2        HBIT = ~HBIT; 
 116   2        Hbitcnt = 0;
 117   2        }
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 3   

 118   1        
 119   1        TH0 = 0xFC;                                  /* set timer period            */
 120   1        TL0 = 0x65;
 121   1        TR0 = 1;                                     /* start timer 0               */
 122   1      
 123   1      if(com1_rec==1)
 124   1        {
 125   2          com1_eofcnt--;
 126   2              if(com1_eofcnt==0)
 127   2                {
 128   3                  com1_eof=1;
 129   3                      com1_rec=0;
 130   3                }
 131   2        } 
 132   1      
 133   1      if(com1_485dlystart==1)
 134   1        {
 135   2          com1_dirdlycnt--;
 136   2              if(com1_dirdlycnt==0)
 137   2                {
 138   3                  com1_485dlyend=1;
 139   3                      com1_485dlystart=0;
 140   3                }
 141   2        } 
 142   1      }
 143          
 144          /*------------------------------------------------
 145          Received data interrupt.
 146          ------------------------------------------------*/
 147          
 148          static void com_isr (void) interrupt 4 using 2
 149          {
 150   1      if (RI != 0)
 151   1        {
 152   2              RI = 0;
 153   2              rxbuff[com1_rxcnt]=SBUF;
 154   2          com1_rec=1; 
 155   2          com1_rxcnt++;
 156   2          com1_eofcnt=com1_eoftm;                
 157   2        }
 158   1      }
 159          
 160          /*------------------------------------------------
 161          Received data interrupt.
 162          ------------------------------------------------*/
 163          
 164          
 165          void main(void)
 166          {
 167   1      unsigned char cnt;
 168   1      
 169   1      for(cnt=0;cnt<9;cnt++)
 170   1       {dly(1000);}
 171   1      init();
 172   1      TransmitChar('V');
 173   1      TransmitChar('E');
 174   1      TransmitChar('R');
 175   1      TransmitChar('1');
 176   1      
 177   1      while(1)
 178   1      {
 179   2      //       Output(0x00);
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 4   

 180   2      //       TransmitChar(P1 & 0x0f);
 181   2      //       dly(60000);
 182   2      //       Output(0xff);
 183   2      //       dly(60000);
 184   2              ModSlave1();
 185   2              if(ndata)
 186   2              {
 187   3               ndata = 0;
 188   3               Output();
*** WARNING C209 IN LINE 188 OF AUXIO.C: '_Output': too few actual parameters
 189   3              }
 190   2      
 191   2      }
 192   1      }
 193          void init (void)
 194          {
 195   1      //idata unsigned char poip;
 196   1      //  P1_5 = 0;                                   //Power on LED
 197   1        LEN = 0;
 198   1        BEN = 1;
 199   1        P0 = 0x00;                                    ;
 200   1        P2 = 0x00;                                    ;
 201   1      //TIMER SETTINGS        
 202   1              TMOD |= 0x21;                   // timer0 = 16bit, timer1 = auto reload
 203   1              TH0      = 0xFC;                // Timer 0 1ms
 204   1              TL0      = 0x65;                //                                                                      
 205   1              TR0 = 1;
 206   1              ET0  = 1;                       // enable timer 0 int                   
 207   1      
 208   1      //SERIAL PORT 0
 209   1         SCON = 0x50;                 // initilise serial port 0 
 210   1         ES = 1;                              //serial int 0    
 211   1      //   TXD = 0;
 212   1      //   RXD = 0;
 213   1      
 214   1      //TIMER SETTINGS        
 215   1              TMOD |= 0x21;                   // timer0 = 16bit, timer1 = auto reload
 216   1              TH1      = 0xFD;                //      Baud rate = 9600
 217   1              TL1      = 0xFD;
 218   1              ET1  = 0;                       //Disable timer 1 int
 219   1              TR1  = 1;                       //start timer 1
 220   1      
 221   1      
 222   1      //ENABLE ALL INTSERRUPTS
 223   1              EA       = 1;                   //enable all interrupt 
 224   1      
 225   1      //ENABLE VARIABLES REQUIRED IN THE PRG
 226   1         com1_rec=0;
 227   1         com1_eofcnt=0;
 228   1         com1_eoftm=EOFTM;
 229   1         com1_eof=0;
 230   1         com1_dirdlytm=5;
 231   1         com1_485dlystart=0;
 232   1         com1_485dlyend=0;
 233   1         com1_rxcnt=0;
 234   1      
 235   1      
 236   1      //poip=  //25-3 2006   p1->p0  // Enter device ID
 237   1         mod1_devid= ~(P1) & 0x0f  ; //(~P1)&0x0f; 
 238   1         mod1_state=1;
 239   1        
 240   1         ndata =0;
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 5   

 241   1         //com1_rxmode();
 242   1      }
 243          
 244          void TransmitChar(unsigned char asc)
 245          {
 246   1       
 247   1              ES = 0;
 248   1              SBUF=asc;
 249   1              while(!TI);
 250   1              TI=0;   
 251   1              ES=1;
 252   1      }
 253          
 254          void ModSlave1(void)
 255          {
 256   1      idata  unsigned char temp1;
 257   1        switch (mod1_state)
 258   1        {
 259   2         case 1:
 260   2                 if(com1_eof==1)
 261   2                 {
 262   3                     com1_eof=0;
 263   3                     com1_rxcnt=0;
 264   3                     temp1=rxbuff[0];
 265   3                     if(temp1==((~P1)&0x0f))
 266   3                       {
 267   4                         mod1_state=2;
 268   4                       }
 269   3                     else
 270   3                       {
 271   4                         mod1_state=1;
 272   4                                               ES=1;
 273   4                       } 
 274   3                 }
 275   2              
 276   2         break;
 277   2      
 278   2         case 2:
 279   2                   validate(rxbuff,txbuff);
 280   2                   if(valid_ok==1)
 281   2                     {
 282   3                      if(flg_read==1)
 283   3                        {
 284   4                         read_response(rxbuff,txbuff,regbuff);
 285   4                        }
 286   3                      else
 287   3                        {
 288   4                         write_response(rxbuff,txbuff);
 289   4                        }
 290   3                     }
 291   2                     mod1_state=3;
 292   2                     com1_offset=0;
 293   2                                 ES=0;
 294   2                                 com1_txcnt=mod_txcnt;
 295   2                     com1_txmode();
 296   2         break;
 297   2      
 298   2         case 3:
 299   2                     com1_txchar=txbuff[com1_offset];
 300   2                     mod1_state=4;
 301   2                     com1_tx();  
 302   2         break;
C51 COMPILER V6.21  AUXIO                                                                  03/25/2008 15:43:14 PAGE 6   

 303   2      
 304   2         case 4:
 305   2                            if(TI==1)
 306   2                    {
 307   3                                  TI=0;
 308   3                      mod1_state=3;
 309   3                      com1_offset++;
 310   3                      com1_txcnt--;
 311   3                      if(com1_txcnt==0)
 312   3                         {
 313   4                                           com1_dirdlycnt=com1_dirdlytm; 
 314   4                           com1_485dlystart=1;
 315   4                           mod1_state=5;
 316   4                           com1_offset=0;                      
 317   4                         } 
 318   3                    }
 319   2         break;
 320   2      
 321   2         case 5:
 322   2                  if(com1_485dlyend==1)
 323   2                    {
 324   3                      com1_rxmode();
 325   3                      com1_485dlystart=0;
 326   3                              com1_485dlyend=0;
 327   3                      mod1_state=1;
 328   3                              ES=1;
 329   3                    }  
 330   2         break;
 331   2      
 332   2         default:
 333   2         break;
 334   2       }
 335   1      }
 336          
 337          void validate(unsigned char rx_buff,unsigned char tx_buff)
 338          {
 339   1      unsigned char temp1;
 340   1      valid_ok=0;
 341   1      flg_read=0;
 342   1      flg_analog=0;
 343   1      flg_single=0;
 344   1      flg_wrongfn=0;
 345   1      //mod_devid=DBYTE[rx_buff];
 346   1      mod_fn=DBYTE[rx_buff+1];
 347   1      
 348   1      switch(mod_fn)
 349   1      {

⌨️ 快捷键说明

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