main.h
上传用户:njxy551199
上传日期:2022-04-06
资源大小:1990k
文件大小:6k
源码类别:

RFID编程

开发平台:

C/C++

  1.   /****************************************************************************
  2. *                                                                           *
  3. * File:         MAIN.H                                                      *
  4. *                                                                           *
  5. *                                                 
  6. *                                                                           *
  7. * Author:       ZUZI                                                        *
  8. *                                                                           *
  9. * Compiler:     KEIL C51 uVision3.3                                         *
  10. *                                                                           *
  11. * Description:  STC89C52-Firmware for HY502 Demo                            *
  12. *                                                                           *
  13. ****************************************************************************/
  14. #ifndef __MAIN_H__
  15. #define __MAIN_H__
  16. //#include "reg52.h"
  17. #include "REG52x2.h"
  18. //#include "at89s52.h
  19. //#include "stc89c51.h"
  20. #include "intrins.h"
  21. #include "string.h"
  22. #define uchar unsigned char
  23. #define uint    unsigned int  
  24. #define SUCCESS 0
  25. #define FAILURE 1
  26. //#define TIMER2           TRUE    
  27. #define MF1_S50 0
  28. #define MF1_S70 1
  29. #define MF0_ULIGHT 2
  30. #define MF1_LIGHT 3
  31. //设置波特率
  32. #define OSC_FREQ                11059200L
  33. #define BAUD_115200             256 - (OSC_FREQ/192L)/115200L   // 255
  34. #define BAUD_57600              256 - (OSC_FREQ/192L)/57600L    // 254
  35. #define BAUD_38400              256 - (OSC_FREQ/192L)/38400L    // 253
  36. #define BAUD_28800              256 - (OSC_FREQ/192L)/28800L    // 252
  37. #define BAUD_19200              256 - (OSC_FREQ/192L)/19200L    // 250
  38. #define BAUD_14400              256 - (OSC_FREQ/192L)/14400L    // 248
  39. #define BAUD_9600               256 - (OSC_FREQ/192L)/9600L     // 244
  40. // Timer2
  41. #define RCAP2_50us             65536L - OSC_FREQ/240417L
  42. #define RCAP2_1ms              65536L - OSC_FREQ/12021L
  43. #define RCAP2_10ms             65536L - OSC_FREQ/1200L
  44. #define RCAP2_1s               65536L - OSC_FREQ/12L
  45. sfr16   RCAP2LH                = 0xCA;
  46. sfr16   T2LH                   = 0xCC;
  47. #define TRUE   1
  48. #define FALSE  0
  49. /*******************************************************************************
  50. * pin declare
  51. *******************************************************************************/
  52. sbit     RST_HY  =P1^2;      // 复位管脚,低电平有效
  53. sbit     NSS     =P1^3; //接HY502 NSS
  54. sbit     MOSI    =P1^7; //接HY502 MOSI
  55. sbit     MISO    =P1^6; //接HY502 MISO
  56. sbit     sig     =P1^4;   // INT0 low level active
  57. sbit     SCL     =P1^5;
  58. //-----------------------------------------------------------------------------------------SendBuffer
  59. unsigned char  idata cp[30];      // HY502 buffer  
  60. unsigned char  idata g_cReceBuf[30]; //uart Receive buffer
  61. unsigned char g_cReceNum; //bytes of received, used in interrupt
  62. bit           g_bReceCommandOk; //flag of command receive OK
  63. bit           g_bReceAA; //flag of last received byte is "0xaa", used in interrupt
  64. bit           g_bCard; //flag of card in
  65. unsigned char idata SelectedSnr[4]; //卡序列号    
  66. //command list in both UART & IIC, with out command header "0xAA, 0xBB" of UART
  67. // CL: command length
  68. // CC: command code
  69. // CD: command data
  70. //                                     CL    CC    CD
  71. //  Set the module Power Down mode
  72. unsigned char ComPWRdwn[]           = {0x02, 0x03};
  73. //  Write E2 data
  74. unsigned char ComWriteE2[]      = {0x09, 0x31, 0x00, 0x00, 0x04, 
  75.                                                                  0x11, 0x00, 0x11, 0x00};
  76. //  Read E2 data
  77. unsigned char ComReadE2[]  ={0x05, 0x30, 0x00, 0x00, 0x04};
  78. // search card and get card serial number
  79. unsigned char code ComSearchCard[]  = {0x03, 0x13, 0x01};
  80. // read block No.4
  81. unsigned char code ComReadBlock4[]  = {0x0a, 0x21, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  82. // read block No.6
  83. unsigned char code ComReadBlock6[]  = {0x0a, 0x21, 0x00, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  84. // write block No.4 with 0x01 to 0x0f
  85. unsigned char  idata ComWriteBlock4[] = {0x1a, 0x22, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  86.                                                    0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  87.                                                    0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  88. //  initialize block No.5 as a purse with value: 0x12345678
  89. unsigned char code ComIntiPurse5[]  = {0x0e, 0x23, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,                             
  90.                                                    0x52, 0x30, 0x20, 0x10};
  91. // read purse value of block No.5
  92. unsigned char code ComReadPurse5[]  = {0x0a, 0x24, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  93. // purse in block No.5 increase with value "2"
  94. unsigned char code ComIncrPurse5[]  = {0x0e, 0x25, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  95.                                                    0x02, 0x00, 0x00, 0x00};
  96. // purse in block No.5 decrease with value "1"
  97. unsigned char code ComDecrPurse5[]  = {0x0e, 0x26, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  98.                                                    0x02, 0x00, 0x00, 0x00};
  99. //  halt the card selected
  100. unsigned char code ComHaltCard[]    = {0x02, 0x12};
  101. void InitializeSystem(); //initialize the MCU system
  102. void AlarmErr(); //beep, indicate a error occured
  103. void ShowError(unsigned char cTimes); //flash LED2, the flash time indicate where is the error
  104. unsigned char SPITesting();          //SPITESTING PROGRAM
  105. #endif
  106. //------------------File end--------------------------