找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1975|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

STC12C5A60S2單片機怎么檢測到斷電?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:575533 發(fā)表于 2019-7-24 14:51 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
STC12C5A60S2  怎么檢測到斷電  馬上保存
  
void lvdint() interrupt 6           //(location at 0033H)
{
}
我的中斷操作為什么不停生效 PCON & 0x20也一直是true
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:575533 發(fā)表于 2019-7-24 15:20 | 只看該作者
或者有什么斷電保存的方法  提供一下也行
回復(fù)

使用道具 舉報

板凳
ID:155507 發(fā)表于 2019-7-24 17:04 | 只看該作者
你這個P4.6口有接嗎?




我給你來個程序試試

  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ù)制代碼




回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表