MCU: STM8S207SB
IO port to be operated: PD7 uses falling edge to trigger interrupt
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 twenty one twenty two twenty three twenty four 25 26 27 28 29 30 31 32 33 34 35 36 | #include #define LED1_FLASH PD_ODR_ODR3 = !PD_ODR_ODR3 // LED1 on the development board is connected to PD3 void GPIO_init(void) { PD_DDR = 0x08; // Configure the direction register PD3 output of the PD port PD_CR1 = 0x08; // Set PD3 to push-pull output PD_CR2 = 0x80; // Enable PD7 external interrupt } void EXTI_init(void) { EXTI_CR1 = 0x80; // PD port falling edge triggers interrupt } #pragma vector=0x02 // This is critical! See the following instructions. __interrupt void EXTI_PD7_TLI(void) { LED1_FLASH; } void init_devices(void) { asm("sim"); // Turn off global interrupts GPIO_init(); EXTI_init(); asm("rim"); // Enable global interrupt } void main( void ) { init_devices(); // There is no program to execute in the main loop while(1); } |
One important point to note here is the external interrupt program of PD7. I looked at the chip manual and found that the interrupt vector number of the PD port external interrupt EXTI3 is 6. Of course, according to IAR rules, the interrupt vector should be added by 2, so I wrote #pragma vector=0x08. As a result, when I pressed the button, the program did not respond and kept interrupting. Next, I had to find another way. After carefully reading the information, I found that PD7 is different from other PD ports. PD7 has a small tail TLI behind it. Looking at the TLI description in the manual, wow, TLI has the highest level of interrupt on the chip and has an independent and dedicated interrupt vector number 0. This is easy to deal with. According to IAR rules, the interrupt vector number in the chip manual + 2 = IAR interrupt vector number. The program was changed to #pragma vector=0x02. I compiled, downloaded, and ran it again, and the button finally obeyed.
Previous article:STM8 uses TIM1 to measure PWM wave
Next article:stm8 pwm implementation core code
Recommended ReadingLatest update time:2024-11-15 08:50
- Popular Resources
- Popular amplifiers
- IAR fully supports the new industrial-grade PX5 real-time operating system
- STM8 C language programming (1) - basic program and startup code analysis
- Description of the BLDC back-EMF sampling method based on the STM8 official library
- ARM Cortex-M4+Wi-Fi MCU Application Guide (Embedded Technology and Application Series) (Guo Shujun)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- TMS320F28335 generates SPWM
- Looking for development tools for Mac OS X
- ESP32_WEB_PUSHER network pusher based on esp32
- Some use cases of MicroPython mpremote tool, chat
- Vicor - Innovative solutions for powering computing applications and data centers
- On the Importance of COVID-19 Isolation
- How to deploy Wi-Fi connectivity for grid protection and control?
- DIY Mechanical Macro Keyboard - Ocreeb
- Common knowledge of inductors
- Love recycling bluetooth chips looking for agents