Yesterday, I was debugging a level interruption. I wanted to change the state of the LED on GP4 when GP1 was pressed. The program was done step by step. GP1 enabled weak pull-up and then connected the button to the ground line. However, when debugging on PICKit3, the LED on the PCB did not turn off. I always thought it was a problem with the code, but later I found that the power supply of PICKit3 was insufficient. It became normal after connecting 5V power. If you are afraid of trouble during debugging, you can connect a 1K~4.7K resistor to GP1 to pull it up and it can be used normally.
The relevant program codes are as follows:
unsigned char GPtemp; //level interrupt reading
void DebounceDelay(unsigned char us)
{
while(us--);
}
void InitGPINT(void) //Level change interrupt See Datasheet page 44
{
nGPPU=0; //The global GPPU bit must be enabled to enable the individual pull-up function.
CMCON0=0B00000101;
TRISIO1=1;
AN1=0;
WPU1=1; //In input mode, internal weak pull-up can be set
GPtemp=GP1;
IOC1=1; //Enable level change interrupt
GPIF=0;
GPIE=1;
}
void interrupt ISR(void) //interrupt processing function
{
/*
if(T0IF) //timing interval 5mS
{
T0IF=0;
MS++;
PWMDelay++;
if(MS>=200) //1 second is up.
{
MS=0;
SEC++;
if(SEC>59)
{
SEC=0;
MIN++;
}
}
TMR0=T0Value; //Reassign value and enter the next cycle
}
*/
if(GPIF) //level interrupt
{
GPIE=0;
GPtemp=GP1;
DebounceDelay(255); //Debounce delay
if(GP1==0)
{
GP4=!GP4;
}
GPIF=0;
GPIE=1;
}
GIE=1; // Enable general interrupt
}
void main(void)
{
InitMCU();
InitSW();
InitGPINT();
InitPWM();
InitAD();
InitT0();
//PEIE=1;
GIE=1;
while(1)
{
LEDBreathe();
}
return;
}
Previous article:BCD code addition program for PIC microcontroller
Next article:PIC microcontroller settings configuration word information
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Power Engineer!!! Click here
- Analog Electronics Simulation
- EEWORLD University ---- ARM Programming
- Principle and Performance Analysis of Satellite Digital Video Broadcasting Receiving System
- [RVB2601 Creative Application Development] 5. Using NTP Timer RTC Clock
- Will the capacitor discharge seek the shortest path?
- C6678 shared memory problem
- Design and practice of common analog systems for e-sports based on TI devices (Part 1)
- The two MOS of synchronous rectification cannot be turned on at the same time, so the concept of dead time appears?
- List of commonly used peripheral chips for DSP