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

📄 enc28j60.lst

📁 58enc28j06protuesuip09.rar
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.15   ENC28J60                                                              08/11/2009 15:07:52 PAGE 1   


C51 COMPILER V8.15, COMPILATION OF MODULE ENC28J60
OBJECT MODULE PLACED IN .\debug\enc28j60.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE enc28j60.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\debug\enc28j60.lst) OBJE
                    -CT(.\debug\enc28j60.obj)

line level    source

   1          #include "enc28j60.h"
   2          #include "spi.h"
   3          
   4          
   5          #define ETHERNET_MIN_PACKET_LENGTH      0x3C
   6          #define ETHERNET_HEADER_LENGTH          0x0E
   7          
   8          #define IP_TCP_HEADER_LENGTH 40
   9          #define TOTAL_HEADER_LENGTH (IP_TCP_HEADER_LENGTH+ETHERNET_HEADER_LENGTH)
  10          
  11          #define MIN(a,b) (a) < (b) ? (a) : (b)
  12          idata u8_t Enc28j60Bank;
  13          idata u16_t NextPacketPtr;
  14          
  15           
  16          void delay_us(int t1)
  17          {
  18   1              while(t1--);
  19   1      }
  20          
  21          void delay_ms(int t1)
  22          { 
  23   1              idata int i; 
  24   1              while(t1--) 
  25   1              {
  26   2                      i=1000;while(i--);
  27   2              }
  28   1      }
  29          
  30          
  31          //*******************************************************************************************
  32          //
  33          // Function : enc28j60ReadOp
  34          // Description : 
  35          //
  36          //*******************************************************************************************
  37          u8_t enc28j60ReadOp(u8_t op, u8_t address)
  38          {
  39   1              u8_t dat1;      
  40   1              CS =0;
  41   1              // issue read command
  42   1              WriteByte(op | (address & ADDR_MASK));  
  43   1              dat1 = ReadByte();
  44   1              // do dummy read if needed (for mac and mii, see datasheet page 29)
  45   1              if(address & 0x80)      dat1 = ReadByte();
  46   1              CS=1;
  47   1              return(dat1);
  48   1      }
  49          //*******************************************************************************************
  50          //
  51          // Function : enc28j60WriteOp
  52          // Description : 
  53          //
  54          //*******************************************************************************************
C51 COMPILER V8.15   ENC28J60                                                              08/11/2009 15:07:52 PAGE 2   

  55          void enc28j60WriteOp(u8_t op, u8_t address, u8_t mydat)
  56          {
  57   1              CS=0;
  58   1              // issue write command
  59   1              WriteByte( op | (address & ADDR_MASK));
  60   1              // write data
  61   1              WriteByte(mydat);
  62   1              CS=1;
  63   1      }
  64          
  65          //*******************************************************************************************
  66          //
  67          // Function : enc28j60_mac_is_linked
  68          // Description : return MAC link status.
  69          //
  70          //*******************************************************************************************
  71          
  72          u8_t enc28j60_mac_is_linked(void)
  73          {
  74   1              if ( (enc28j60_read_phyreg(PHSTAT1) & PHSTAT1_LLSTAT ) )
  75   1                 {    
  76   2                      return 1;           /*ok*/
  77   2                 }
  78   1              else
  79   1                 {       
  80   2                      return 0;           /*error*/
  81   2                 }
  82   1      }
  83          
  84          
  85          
  86          //*******************************************************************************************
  87          //
  88          // Function : icmp_send_request
  89          // Description : Send ARP request packet to destination.
  90          //
  91          //*******************************************************************************************
  92          void enc28j60SetBank(u8_t address)
  93          {
  94   1              // set the bank (if needed)
  95   1              if((address & BANK_MASK) != Enc28j60Bank)
  96   1              {
  97   2                      // set the bank
  98   2                      enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, (ECON1_BSEL1|ECON1_BSEL0));
  99   2                      enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, (address & BANK_MASK)>>5);
 100   2                      Enc28j60Bank = (address & BANK_MASK);
 101   2              }
 102   1      }
 103          //*******************************************************************************************
 104          //
 105          // Function : icmp_send_request
 106          // Description : Send ARP request packet to destination.
 107          //
 108          //*******************************************************************************************
 109          u8_t enc28j60Read(u8_t address)
 110          {
 111   1              // select bank to read
 112   1              enc28j60SetBank(address);       
 113   1              // do the read
 114   1              return enc28j60ReadOp(ENC28J60_READ_CTRL_REG, address);
 115   1      }
 116          //*******************************************************************************************
C51 COMPILER V8.15   ENC28J60                                                              08/11/2009 15:07:52 PAGE 3   

 117          //
 118          // Function : icmp_send_request
 119          // Description : Send ARP request packet to destination.
 120          //
 121          //*******************************************************************************************
 122          void enc28j60Write(u8_t address, u8_t mydat)
 123          {
 124   1              // select bank to write
 125   1              enc28j60SetBank(address);
 126   1      
 127   1              // do the write
 128   1              enc28j60WriteOp(ENC28J60_WRITE_CTRL_REG, address, mydat);
 129   1      }
 130          //*******************************************************************************************
 131          //
 132          // Function : icmp_send_request
 133          // Description : Send ARP request packet to destination.
 134          //
 135          //*******************************************************************************************
 136          
 137          u16_t enc28j60_read_phyreg(u8_t address)
 138          {
 139   1              u16_t mydat;
 140   1              
 141   1              // set the PHY register address
 142   1              enc28j60Write(MIREGADR, address);
 143   1              enc28j60Write(MICMD, MICMD_MIIRD);
 144   1              
 145   1              // Loop to wait until the PHY register has been read through the MII
 146   1              // This requires 10.24us
 147   1              while( (enc28j60Read(MISTAT) & MISTAT_BUSY) );
 148   1              
 149   1              // Stop reading
 150   1              //enc28j60Write(MICMD, MICMD_MIIRD);
 151   1              enc28j60Write(MICMD,0x00);        /*by gjk 09/03/09  赋值0x00*/
 152   1              // Obtain results and return
 153   1              mydat = enc28j60Read ( MIRDH );
 154   1              mydat<<=8;       /*jerkoh090120*/
 155   1              mydat |= enc28j60Read ( MIRDL );
 156   1              
 157   1      
 158   1              return mydat;
 159   1      }
 160          
 161          //*******************************************************************************************
 162          //
 163          // Function : icmp_send_request
 164          // Description : Send ARP request packet to destination.
 165          //
 166          //*******************************************************************************************
 167          void enc28j60PhyWrite(u8_t address, u16_t mydat)
 168          {
 169   1              // set the PHY register address
 170   1              enc28j60Write(MIREGADR, address);
 171   1              // write the PHY data
 172   1              enc28j60Write(MIWRL, mydat & 0x00ff);
 173   1              enc28j60Write(MIWRH, mydat >> 8);
 174   1              // wait until the PHY write completes
 175   1              while(enc28j60Read(MISTAT) & MISTAT_BUSY)
 176   1              {
 177   2                      delay_us(15);
 178   2              }
C51 COMPILER V8.15   ENC28J60                                                              08/11/2009 15:07:52 PAGE 4   

 179   1      }
 180          
 181          void enc28j60ReadBuffer(u16_t len, u8_t* dat)
 182          {
 183   1          // assert CS
 184   1          // ENC28J60_CONTROL_PORT &= ~(1<<ENC28J60_CONTROL_CS);
 185   1          CS = 0;
 186   1          // issue read command
 187   1              //SPDR = ENC28J60_READ_BUF_MEM;
 188   1              WriteByte(ENC28J60_READ_BUF_MEM);
 189   1          //while(!(SPSR & (1<<SPIF)));
 190   1          while(len--)
 191   1          {
 192   2              // read data
 193   2                      //SPDR = 0x00;
 194   2              //while(!(SPSR & (1<<SPIF)));
 195   2              //*dat++ = SPDR;
 196   2                      *dat++ = ReadByte();
 197   2          }   
 198   1          // release CS
 199   1              //ENC28J60_CONTROL_PORT |= (1<<ENC28J60_CONTROL_CS);
 200   1              CS = 1;
 201   1      }
 202          
 203          void enc28j60WriteBuffer(u16_t len, u8_t* dat)
 204          {
 205   1          // assert CS
 206   1              //ENC28J60_CONTROL_PORT &= ~(1<<ENC28J60_CONTROL_CS);
 207   1              CS = 0;
 208   1          
 209   1          // issue write command
 210   1              //SPDR = ENC28J60_WRITE_BUF_MEM;
 211   1              WriteByte(ENC28J60_WRITE_BUF_MEM);
 212   1         // while(!(SPSR & (1<<SPIF)));
 213   1          while(len--)
 214   1          {
 215   2              // write data
 216   2                      //SPDR = *dat++;
 217   2              //while(!(SPSR & (1<<SPIF)));
 218   2                      WriteByte(*dat++);
 219   2          }   
 220   1          // release CS
 221   1          //ENC28J60_CONTROL_PORT |= (1<<ENC28J60_CONTROL_CS);
 222   1              CS = 1;
 223   1      }
 224          
 225          
 226          
 227          
 228          
 229          void enc28j60PacketSend(u16_t len, u8_t* packet)
 230          {
 231   1      
 232   1      
 233   1      
 234   1          // Set the write pointer to start of transmit buffer area
 235   1              enc28j60Write(EWRPTL, TXSTART_INIT);
 236   1          enc28j60Write(EWRPTH, TXSTART_INIT>>8);
 237   1      
 238   1          // Set the TXND pointer to correspond to the packet size given
 239   1              enc28j60Write(ETXNDL, (TXSTART_INIT+len));
 240   1          enc28j60Write(ETXNDH, (TXSTART_INIT+len)>>8);
C51 COMPILER V8.15   ENC28J60                                                              08/11/2009 15:07:52 PAGE 5   

 241   1      
 242   1          // write per-packet control byte

⌨️ 快捷键说明

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