松翰5703例程-WDT

  1. //--------------------------------------------------------------------------
  2. //Filename        : STOP_Mode.c
  3. //Function        : Use watch dog timer to Power save application when SN8F5708 run as stop mode.
  4. //description        : SN8F5708 be waked up by watch dog reset.
  5. //--------------------------------------------------------------------------
  6. //Note:
  7. //     1)User need to add the STARTUP.A51 file which in this project to your project.
  8. //     2)The STARTUP.A51 file has been modified for the Watchdog wakeup function.
  9. //     3)User need to Reset the source which has used according to the PFLAG register.
  10. //--------------------------------------------------------------------------

  11. #include <SN8F5703.h>

  12. #define uchar unsigned char
  13. #define uint unsigned int

  14. uchar RCycle_CNT;
  15. //--------------------------------------------------------------------------
  16. //subroutine        : main()
  17. //Function                :
  18. //--------------------------------------------------------------------------
  19. void main(void)
  20. {
  21. CLKSEL = 0x03;                                //Fcpu=Fosc/16
  22. //        CLKSEL = 0x04;                                //Fcpu=Fosc/8
  23. //        CLKSEL = 0x05;                                //Fcpu=Fosc/4
  24. CLKCMD = 0x69;
  25. CKCON = 0x11;

  26. WDTR = 0X5A;

  27. if((PFLAG&0X40)==0X40)        //Watchdog Reset
  28. {
  29. P0UR = 0X00;
  30. P0 = 0X00;
  31. P0M = 0XFF;

  32. P1UR = 0X00;
  33. P1 = 0X00;
  34. P1M = 0XFF;

  35. P2UR = 0X00;
  36. P2 = 0X00;
  37. P2M = 0XFF;
  38. }
  39. else                                                                                //Other Reset
  40. {
  41. P0UR = 0X00;
  42. P0 = 0XFF;
  43. P0M = 0XFF;

  44. P1UR = 0X00;
  45. P1 = 0X00;
  46. P1M = 0XFF;

  47. P2UR = 0X00;
  48. P2 = 0X00;
  49. P2M = 0XFF;
  50. }

  51. while(1)
  52. {
  53. WDTR = 0X5A;
  54. RCycle_CNT++;
  55. P2 = RCycle_CNT;                //P2 output registor data
  56. P1W = 0X00;                                        //Set P1 port wake up source, if enable, user need to set port as input mode
  57. STOP();
  58. }
  59. }