Working principle: RB4:RB7 is the input state of the level change interrupt pin and compares it with the value of the latch of PORTB read last time. When the two sets of data are different, an interrupt occurs. When the level of part of these four pins changes, the final OR will be taken. As long as the input state of one pin changes, an interrupt change will occur.
Note: When entering the interrupt service subroutine, you must read or write the value of the PORTB latch, so that the comparison of the two sets of data will end, and then clear the interrupt flag. If the value of PORTB is not read, the comparison of the two sets of data will always exist. It is useless to clear the interrupt flag (RBIF) first, and RBIF will always be set. For example, the following example:
/*This is a photoelectric encoder (code disk) reading using INT interrupt and level change interrupt*/
void
interrupt on_change()
{
if(INTF)
{
f_r++;
INTF=0;
}
if(RBIF&&RB4) //High level count
{
RB4=~RB4; //Read or write the value of PORTB latch first
f_l++;
RBIF=0; //Clear interrupt flag (RBIF)
}
else {RB4=~RB4; RBIF=0;} //Low level
}
The following program is the problem that has been bothering us during the experiment, that is, there is no interrupt.
Incorrect usage, the latch value is not read
void
interrupt on_change()
{
if(INTF)
{
f_r++;
INTF=0;
}
if(RBIF&&RB4)
{
f_l++;
RBIF=0;//
}
else {RBIF=0;}
}
Previous article:PIC 8-bit microcontroller instruction reading skills
Next article:How to design the AD conversion module of pic877a microcontroller
- 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
- A collection of practical automotive electronics information, free points download for a limited time
- Analyze whether it is the rising edge or the falling edge that reads and writes data
- How to design the step-up transformer for electrostatic generator
- [Sipeed LicheeRV 86 Panel Review] 5-Tina System Image Compilation Test
- Recruiting QT software engineers (PC side), QT software engineers (Linux side), hardware design engineers, R&D test engineers,...
- CC2640R2F: A must-read for beginners
- Analysis of the interrupt process of C6000 DSP system
- [Zero-knowledge ESP8266 Tutorial] Zero-knowledge WIFI Tutorial - http WEB Server Example
- 【TI recommended course】#TI millimeter wave radar technology introduction#
- 【DIY fan】Unboxing