標(biāo)題: STC12C5A60S2單片機(jī)怎么檢測(cè)到斷電? [打印本頁(yè)]

作者: 漢神俊    時(shí)間: 2019-7-24 14:51
標(biāo)題: STC12C5A60S2單片機(jī)怎么檢測(cè)到斷電?
STC12C5A60S2  怎么檢測(cè)到斷電  馬上保存
  
void lvdint() interrupt 6           //(location at 0033H)
{
}
我的中斷操作為什么不停生效 PCON & 0x20也一直是true
作者: 漢神俊    時(shí)間: 2019-7-24 15:20
或者有什么斷電保存的方法  提供一下也行
作者: angmall    時(shí)間: 2019-7-24 17:04
你這個(gè)P4.6口有接嗎?




我給你來(lái)個(gè)程序試試

  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU Limited ---------------------------------------------*/
  3. /* --- STC12C5Axx Series MCU Power-Down wakeup by LVD(P4.6) Demo ---*/
  4. /* --- Mobile: (86)13922805190 -------------------------------------*/
  5. /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
  6. /* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/
  7. /* If you want to use the program or the program referenced in the  */
  8. /* article, please specify in which data and procedures from STC    */
  9. /*------------------------------------------------------------------*/

  10. #include "reg51.h"
  11. #include "intrins.h"

  12. sfr WAKE_CLKO = 0x8f;
  13. sfr P4SW = 0xbb;

  14. sbit ELVD = IE^6;

  15. //External interrupt0 service routine
  16. void lvdint() interrupt 6           //(location at 0033H)
  17. {
  18.     PCON &= 0xdf;                   //clear LVD flag
  19. }

  20. void main()
  21. {
  22.     P4SW &= 0xbf;                   //Set P4.6 as LVD function pin
  23.     WAKE_CLKO = 0x08;               //enable LVD signal wakeup MCU from power-down mode
  24.     ELVD = 1;                       //enable LVD interrupt
  25.     EA = 1;                         //open global interrupt switch

  26.     while (1)
  27.     {
  28.         while (PCON & 0x20)
  29.         {
  30.             PCON &= 0xdf;               //clear LVD flag
  31.             _nop_();
  32.             _nop_();
  33.             _nop_();
  34.             _nop_();
  35.         }
  36.         _nop_();
  37.         _nop_();
  38.         PCON = 0x02;                 //MCU power down
  39.         _nop_();
  40.         _nop_();
  41.         P1++;
  42.     }
  43. }

復(fù)制代碼









歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1