/*******************************
RB0 of PORTB can be used as an external interrupt signal input, and can generate an interrupt response to the rising or falling edge transition of the input signal.
To implement the RB0/INT interrupt source, the software initialization setting steps are as follows:
1, RB0/INT pin is in input mode, TRISB0 = 1;
2, INTEDG = 1, the rising edge of the input signal on RB0 generates an interrupt; INTEDG = 0, the falling edge interrupt
3. Clear INTF = 0 and make sure the interrupt flag is 0 before a valid interrupt occurs;
4, INTE = 1, enable RB0/INT interrupt response.
5. GIE = 1, turn on the general interrupt enable
6. After the interrupt occurs, query the INTF bit;
7. If INTF = 1, there is an interrupt. After processing, the software must clear the INTF interrupt flag.
********************************/
#include
#include "../head/config.h"
__CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);
//HS oscillation, disable watchdog, low voltage programming off, start delay timer
void delay1ms(uint DelayTime);
void main(void)
{
TRISB = 0x01;
INTEDG = 0;
INTF = 0;
INTE = 1;
GIE = 1;
PORTD = 0xff;
TRISD = 0x00;
while(1){}
}
void interrupt ISR(void)
{
if(INTF == 1)
{
INTF = 0;
delay1ms(20);
if(RB0 == 0)
{
PORTD = ~PORTD;
}
}
}
void delay1ms(uint DelayTime)
{ uint temp;
for(;DelayTime>0;DelayTime--)
{ for(temp=0;temp<270;temp++)
{;}
}
}
Previous article:PIC microcontroller learning 7 TMR1
Next article:PIC learning 6 PORTB port
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- 【Goodbye 2021, Hello 2022】At the end of a busy year
- 51 MCU calls the delay function in the for loop
- Bicycle computer based on GD32E231C8T6
- This week's highlights
- STM device I2C drives 0.96 OLED display
- Crazy Shell AI open source drone serial port (optical flow acquisition)
- Experience in using HGI MCU - Avoid pitfalls
- Power consumption test method for low power consumption devices
- Using WS2812 on ESP32-S2-Saola-1
- Can the LF356 op amp amplify current without any peripheral devices?