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

📄 reader.lst

📁 基于at89s52的读mifare1卡c51源程序.单片机与rfid读卡模块yhy502相连。单片机与上位机通过串口进行通信
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.12   READER                                                                03/07/2009 23:13:12 PAGE 1   


C51 COMPILER V8.12, COMPILATION OF MODULE READER
OBJECT MODULE PLACED IN Reader.OBJ
COMPILER INVOKED BY: G:\Program Files\keil\C51\BIN\C51.EXE Reader.c BROWSE INCDIR(G:\Program Files\keil\C51\INC\Atmel) D
                    -EBUG OBJECTEXTEND

line level    source

   1          #include<reg52.h>
   2          #include<intrins.h>
   3          sfr16   RCAP2LH                = 0xCA;
   4          sfr16   T2LH                   = 0xCC;
   5          #define TRUE   1
   6          #define FALSE  0
   7          #define SUCCESS 1
   8          #define FAILURE 0
   9          
  10          
  11          // 定义IIC端口
  12          sbit     SDA        =    P1^6;
  13          sbit     SCL        =    P1^7;
  14          
  15          unsigned char idata SelectedSnr[4];//卡序列号 
  16          
  17          //-----------------------------------------------------------------------------------------SendBuffer
  18          unsigned char  data cp[30];      // HY502 buffer  
  19          unsigned char  idata g_cReceBuf[30];    //uart Receive buffer
  20          
  21          unsigned char g_cReceNum;               //bytes of received, used in interrupt
  22          bit           g_bReceCommandOk; //flag of command receive OK
  23          bit           g_bReceAA;                //flag of last received byte is "0xaa", used in interrupt
  24          bit           g_bCard;                  //flag of card in
  25          
  26          
  27          //设置波特率
  28          #define OSC_FREQ                11059200L
  29          
  30          #define BAUD_115200             256 - (OSC_FREQ/192L)/115200L   // 255
  31          #define BAUD_57600              256 - (OSC_FREQ/192L)/57600L    // 254
  32          #define BAUD_38400              256 - (OSC_FREQ/192L)/38400L    // 253
  33          #define BAUD_28800              256 - (OSC_FREQ/192L)/28800L    // 252
  34          #define BAUD_19200              256 - (OSC_FREQ/192L)/19200L    // 250
  35          #define BAUD_14400              256 - (OSC_FREQ/192L)/14400L    // 248
  36          #define BAUD_9600               256 - (OSC_FREQ/192L)/9600L     // 244
  37          // Timer2
  38          #define RCAP2_50us             65536L - OSC_FREQ/240417L
  39          #define RCAP2_1ms              65536L - OSC_FREQ/12021L
  40          #define RCAP2_10ms             65536L - OSC_FREQ/1200L
  41          #define RCAP2_1s               65536L - OSC_FREQ/12L
  42          
  43          
  44          
  45          #define   CMD_OK           0
  46          #define   CMD_ERR      1 
  47          
  48          // Define the commands
  49          #define   PCD_PN       0x01               // 设备型号
  50          #define   PCD_SN       0x02               // 设备序列号
  51          #define   PWR_DOWN     0x03               //设备掉电,需重新加电复位!,不带DOG时有效
  52          #define   BAUD_SET     0x04               //波特率设置
  53          #define   FW_REL       0x10               //PCD固件版本号
  54          #define   SOFTDOWN     0x11               //HY502模块软掉电
C51 COMPILER V8.12   READER                                                                03/07/2009 23:13:12 PAGE 2   

  55          #define   HALT_CARD    0x12               //中止卡操作
  56          #define   AUTOSEARCH   0x13               //自动寻卡
  57          #define   BEEP         0x14               //蜂鸣器开关
  58          #define   BEEP_TIME    0x15               //鸣响时间
  59          #define   CARD_TYPE    0x19               //读取卡类型
  60          #define   CARD_SN      0x20               //读卡序列号
  61          #define   READ_BLOCK   0x21               //读块数据
  62          #define   WRITE_BLOCK  0x22               //写块数据
  63          #define   INIT_PURSE   0x23               //初始化钱包
  64          #define   READ_PURSE   0x24               //读钱包
  65          #define   ADD_PURSE    0x25               //钱包充值
  66          #define   DEC_PURSE    0x26               //钱包扣款
  67          #define   READ_SECTOR  0x2a       // 读扇区
  68          #define   WRITE_SECTOR 0x2b       // 写扇区
  69          #define   READ_E2      0x30       // 读E2
  70          #define   WRITE_E2     0x31       // 写E2          
  71          
  72          
  73          // Define the error commands return from HY502 chip
  74          
  75          #define   ERR_HALT         0xed           //中止卡操作错误
  76          #define   ERR_AUTO         0xec           //自动寻卡错误
  77          #define   ERR_TYPE         0xe6           //读取卡类型错误
  78          #define   ERR_SN           0xdf           //读卡序列号错误
  79          #define   ERR_READ_BLOCK   0xde           //读块数据错误
  80          #define   ERR_WRITE_BLOCK  0xdd           //写块数据错误
  81          #define   ERR_INIT_PURSE   0xdc           //初始化钱包错误
  82          #define   ERR_READ_PURSE   0xdb           //读钱包错误
  83          #define   ERR_ADD_PURSE    0xda           //钱包充值错误
  84          #define   ERR_DEC_PURSE    0xd9           //钱包扣款错误
  85          ///////////////////////////////////////////////////////////////////
  86          
  87          char code reserve[3]_at_ 0x3b; //保留0x3b开始的3个字节
  88          
  89          
  90          void InitializeSystem()
  91          {
  92   1        
  93   1              unsigned char i=0;
  94   1              for(i=0;i<30;i++)
  95   1                      cp[i]='\0';
  96   1      
  97   1        SCON = 0x50; //设定串口工作方式1,接收使能
  98   1        PCON = 0x00; //波特率不倍增
  99   1      
 100   1        TMOD = 0x20; //定时器1工作于8位自动重载模式, 用于产生波特率
 101   1        EA = 1;
 102   1        TL1 = 0xfd;
 103   1        TH1 = 0xfd; //波特率9600
 104   1        TR1 = 1;
 105   1              g_bReceCommandOk=0;                                                             
 106   1      }
 107          
 108          /////////////////////////////////////////////////////////////////////////////////////////////////////
 109          // 延时函数
 110          void delay(unsigned int x)
 111          {
 112   1              while(x)
 113   1              {
 114   2                      x--;
 115   2              }
 116   1      }
C51 COMPILER V8.12   READER                                                                03/07/2009 23:13:12 PAGE 3   

 117          
 118          ///////////////////////////////////////////////////////////////////////
 119          // Delay 50us
 120          ///////////////////////////////////////////////////////////////////////
 121          void delay_50us(unsigned char _50us)
 122          {
 123   1        RCAP2LH = RCAP2_50us;
 124   1        T2LH    = RCAP2_50us;
 125   1        ET2 = 0;      // Disable timer2 interrupt
 126   1        T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
 127   1      
 128   1        while (_50us--)
 129   1        {
 130   2              while (!TF2);
 131   2              TF2 = FALSE;
 132   2        }
 133   1      
 134   1        TR2 = FALSE;
 135   1      }
 136          
 137          void delay_1ms (unsigned int _1ms)
 138          {
 139   1      
 140   1        RCAP2LH = RCAP2_1ms;
 141   1        T2LH    = RCAP2_1ms;
 142   1        ET2 = 0;      // Disable timer2 interrupt
 143   1        T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
 144   1      
 145   1        while (_1ms--)
 146   1        {
 147   2              while (!TF2);
 148   2              TF2 = FALSE;
 149   2        }
 150   1        TR2 = FALSE;
 151   1      
 152   1      }
 153          
 154          
 155          //---------------------IIC function define ---------------------------------------------
 156          #define READ_HY502              0xA1           //module address (综合型的是默认内部地址,通过模块上的地址设置而不是引
             -脚上的)
 157          #define WRITE_HY502         0xA0           //这点区别于独立的iic模式,独立的模式是指的引脚上的地址!
 158          /*****************************************************************************
 159          *function: IIC start condition
 160          *****************************************************************************/
 161          void I2CStart(void)
 162          {
 163   1              SDA = 1;
 164   1              SCL = 1;
 165   1              SDA = 0;
 166   1              _nop_();
 167   1              SCL = 0;
 168   1      }
 169          /*****************************************************************************
 170          *function: IIC stop condition
 171          *****************************************************************************/
 172          void I2CStop(void)
 173          {
 174   1              SCL = 0;
 175   1              SDA = 0;
 176   1              _nop_();
 177   1              SCL = 1;
C51 COMPILER V8.12   READER                                                                03/07/2009 23:13:12 PAGE 4   

 178   1              SDA = 1;
 179   1      }
 180          /*****************************************************************************
 181          *function: IIC wait ACK
 182          *****************************************************************************/
 183          bit I2CWaitAck(void)
 184          {
 185   1              unsigned char cErrTime = 255;
 186   1              SDA = 1;
 187   1              _nop_();
 188   1              SCL = 1;
 189   1              while(SDA)
 190   1              {
 191   2                      cErrTime--;
 192   2                      delay(10);
 193   2                      if (0 == cErrTime)
 194   2                      {
 195   3                              I2CStop();
 196   3                              return FAILURE;
 197   3                      }

⌨️ 快捷键说明

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