Timer.h
上传用户:xmyjxjd
上传日期:2013-05-04
资源大小:1517k
文件大小:2k
开发平台:

C/C++

  1. #include "HEADERMain_def.h"
  2. // For 24.576MHz crystal
  3. // Timer Freq.      : 24.576MHz / 12 = 2.048MHz -> 0.488us
  4. #if (IRPOLLING)
  5. // Timer0 Period    : (0xffff - 0xfcff) / 2.048 = 375us -> 0.375ms
  6. #define TIME0_COUNTER_LBYTE     0xFF
  7. #define TIME0_COUNTER_HBYTE     0xFC
  8. #else
  9. // Timer0 Period    : (0xffff - 0x5fff) / 2.048 = 20000us -> 20ms
  10. #if(MCU_TYPE == MCU_WINBOND)
  11. #define TIME0_COUNTER_LBYTE     0xFF
  12. #define TIME0_COUNTER_HBYTE     0x5F
  13. #else
  14. #define TIME0_COUNTER_LBYTE     0xFF//0xDF
  15. #define TIME0_COUNTER_HBYTE     0x5F//0xB1
  16. #endif
  17. #endif
  18. // Timer1 Period    : (0xffff - 0xf7ff) / 2.048 =  1000us ->  1ms
  19. #if(MCU_TYPE == MCU_WINBOND)
  20. #define TIME1_COUNTER_LBYTE     0xFF
  21. #define TIME1_COUNTER_HBYTE     0xF7
  22. #define TIME1_COUNTER_HHBYTE    0xFB
  23. #else
  24. #define TIME1_COUNTER_LBYTE     0x80//0xFF//0x17
  25. #define TIME1_COUNTER_HBYTE     0xF8//0xF7//0xFC
  26. #define TIME1_COUNTER_HHBYTE    0xFB //anson 050519
  27. #endif
  28. #ifdef __TIMER__
  29. bit bNotify_Timer0_Int  = 0;
  30. bit bNotify_Timer1_Int  = 0;
  31. unsigned char   idata   ucTimerCounter = 0;
  32. void Delay_Xms(unsigned char x);    // For delay 0 ~ 255 ms
  33. /*
  34. // For 24MHz crystal
  35. // Timer Freq.      : 24MHz / 12 = 2MHz -> 0.5us
  36. #if (IRPOLLING)
  37. // Timer0 Period    : (0xffff - 0xfd11) * 0.5 = 375us -> 0.375ms
  38. #define TIME0_COUNTER_LBYTE     0x11
  39. #define TIME0_COUNTER_HBYTE     0xFD
  40. #else
  41. // Timer0 Period    : (0xffff - 0x63bf) * 0.5 = 20000us -> 20ms
  42. #define TIME0_COUNTER_LBYTE     0xBF
  43. #define TIME0_COUNTER_HBYTE     0x63
  44. #endif
  45. // Timer1 Period    : (0xffff - 0xf82f) * 0.5 =  1000us ->  1ms
  46. #define TIME1_COUNTER_LBYTE     0x2F
  47. #define TIME1_COUNTER_HBYTE     0xF8
  48. */
  49. #else
  50. extern bit bNotify_Timer0_Int;
  51. extern bit bNotify_Timer1_Int;
  52. extern void Delay_Xms(unsigned char x);    // For delay 0 ~ 255 ms
  53. #endif