PIC12F508 MCU Learning Part 3 - Wake up by pressing a button

Publisher:自由漫步Latest update time:2015-01-16 Source: 51heiKeywords:PIC12F508 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The PIC12F508 microcontroller has no interrupts, and key interrupts can only be used in a query mode.
 
The compiler used is XC8, and the compilation environment IDE used is MPLAB X IDE.
 
The downloader is PICKIT3.
 
//***************************************************
//           __________________
//       VDD-| 1            8 |-VSS
// GP5-| 2 27 |-GP0/DAT
//       GP4-| 3           26 |-GP1/CLK
//GP3/RMCLR--| 4           25 |-GP2
//           |________________|
//               12F508
//***************************************************
 
//Watchdog sleep wakeup
//Button wake up
 
#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
#define LED1 GP5
#define LED2 GP4
#define KEY  GP3
bit   KEY_F;
uchar count;
//flying GP3_F;
void Init()
{
   TRIS=~0x3F; //GP3 input, other outputs
   // OPTION = 0x07; //This register is reset to 1 on power-on
   // OPTION=nGPWU|nGPPU|PSA|PS1|PS2; //Pin interrupt wake-up disable weak pull-up disable timer allocation watchdog time is 18Ms*64=1.152S
    OPTION=0x1E; // Pin interrupt wake-up enable weak pull-up enable The timer allocates the watchdog time to be 18Ms*64=1.152S
  // TMR0=0x63;   //10ms
}
 void  main()
{  
 Heat();   
while(1)
{
    if((GPWUF==1)&&(KEY==0)) //Interrupt wakeup caused by pin
   {
     LED2=~LED2;
   }
    if(nTO==0) //Reset caused by watchdog
   {
      LED1=~LED1;
   }
         KEY_F=KEY; //Read the key status before sleep.
         SLEEP();
    }
}
Keywords:PIC12F508 Reference address:PIC12F508 MCU Learning Part 3 - Wake up by pressing a button

Previous article:Fan controller made by PIC12F508
Next article:PIC12F508 MCU Learning Part 1 - Timer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号