专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

PIC12F508单片机学习之二—看门狗和休眠模式试用

作者:听雨心情   来源:听雨心情   点击数:  更新时间:2014年06月20日   【字体:

 

 
 
PIC12F508单片机是没有中断的,定时器只能是查询方式。
 
编译器用的XC8,编译环境IDE用的是MPLAB X IDE。
 
下载器是PICKIT3.
 
//***************************************************
//           __________________
//       VDD-| 1            8 |-VSS
//       GP5-| 2           27 |-GP0/DAT
//       GP4-| 3           26 |-GP1/CLK
//GP3/RMCLR--| 4           25 |-GP2
//           |________________|
//               12F508
//***************************************************
// 看门狗和休眠模式试用
 
 
#include
#include
 
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
 
// CONFIG
#pragma config OSC = IntRC      // Oscillator Selection bits (internal RC oscillator)
#pragma config WDT = ON        // Watchdog Timer Enable bit (WDT Enable )
#pragma config CP = OFF         // Code Protection bit (Code protection off)
#pragma config MCLRE = OFF      // GP3/MCLR Pin Function Select bit (GP3/MCLR pin function is digital input, MCLR internally tied to VDD)
 
#define uchar unsigned char
#define uint unsigned int
uchar  count;
//uchar  GP3_F;
void Init()
{
    TRIS=~0x3F;  //GP3输入,其它输出
    OPTION=0xFE; //定时器分配看门狗 时间是18Ms*64=1.152S
}
 void  main()
{  
 Init();
 
   
while(1)
     {
 
    if(nTO==0)      //看门狗引起的复位
   {
      GP2=~GP2;
   }    
         SLEEP();
    }
}
 
关闭窗口