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();
}
}
Previous article:Fan controller made by PIC12F508
Next article:PIC12F508 MCU Learning Part 1 - Timer
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- 【Android Development Learning Road】Three-- Binder Initial Implementation
- Award-winning live broadcast: ams projection lighting (MLA) enhances the communication between cars and roads
- MSP430F5529 USB Experimenter Board
- pyESP32 Pinout
- Getting Started with I2C on MSP MCUs
- 【AT-START-F425 Review】No.03 Debugging serial port, timer and main system frequency
- The most complete and easy-to-understand PPT on 5G (worth collecting)
- UN Secretary-General Kofi Annan has clearly expressed his support for Japan to become a permanent member of the UN Security Council.
- Consulting circuit!!!
- How to use the Pioneer graphical pin configuration tool