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