stm8s development (VI) Use of EXIT: Make an external interrupt button

Publisher:快乐舞蹈Latest update time:2020-09-02 Source: eefocusKeywords:stm8s  EXIT Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  In the previous articles, the use of GPIO: Light up the LED! only described the output of the IO port, not the input. Because I recommend using the interrupt method for IO as input, which can greatly reduce the CPU running time. The most commonly used function is the button function, of course, there is also the function of communicating with other chips.


  The previous article mentioned that GPIO can be set as interrupt input through registers.

  Configuration mode DDRCR1CR2 Configuration mode pull-up resistor

  Input 000 Suspension input OFF

  010 Pull-up input ON

  001 Interrupt suspension input OFF

  011 Interrupt pull-up input ON

  Output 100 Open drain output OFF

  110 push-pull output

  1x1 output (maximum speed 10MHZ)

  xxxTrue open-drain output is not used

  Here we choose PC3 as the external interrupt

  void EXIT_GPIO_Init(void)

  {

  PC_DDR &= 0xf7;

  PC_CR1 |= 0x08; // Set PC3 to interrupt pull-up input

  PC_CR2 |= 0x08;

  EXTI_CR1 = 0x20; //PC is set to falling edge trigger

  }

  It should be noted here that the interrupt vector specifies the PC, that is, if several PC ports are set as interrupts, as long as one of the interrupts is responded to, the same function will be entered.


  If you have several buttons on the same port, you can get the status of an IO port after entering the interrupt function, determine which IO is interrupted, and then perform corresponding operations.


  #pragma vector = EXIT_PORTC_vector //0x07

  __interrupt void EXIT_PORTC_RQHandler(void) //Interrupt service function

  {

  if((PC_IDR & 0x08)==0)

  {

  delay_nms(50); //delay 50ms, debounce

  if((PC_IDR & 0x08)==0) // Check if it is pressed

  {

  while(!(PC_IDR & 0x08)); // Release detection

  //ALL

  }

  }

  }


  Since mechanical buttons are used, there will generally be a mechanical jitter process, so after entering the interrupt function, we first do a jitter elimination process, so that we can determine the state of the button, and also prevent jitter from causing repeated interrupt functions. Finally, add a release detection to determine that the button action is completed. (TODO here you can add the operations you need)


  Attached is the project of stm8s in IAR environment, including the initialization code of on-chip hardware such as SPI, IIC, PWM, AWU, USART, EEPROM, etc.

  http://download.csdn.net/detail/devintt/9454188

Keywords:stm8s  EXIT Reference address:stm8s development (VI) Use of EXIT: Make an external interrupt button

Previous article:stm8s development (eight) use of IIC: IIC host communication!
Next article:STM8S external interrupt keeps going

Recommended ReadingLatest update time:2024-11-23 19:17

STM8S_002_TIM precise delay (blocking)
Ⅰ. Write in front In some specific situations, precise delay (us level) is required, especially for the underlying driver. If software delay is used, the delay will change with the change of system clock and various factors. Therefore, TIM precise delay is required.   Blocking delay: From the start to the end of the d
[Microcontroller]
STM8S_002_TIM precise delay (blocking)
STM8S Self-study Notes-001 Introduction to STM8
Overview The developer of the STM8 microcontroller is STMicroelectronics (ST), which was launched in 2009. It has the advantages of a 3-stage pipeline architecture, high cost performance, and convenient development. According to different application scenarios, it is divided into three series: STM8S, STM8L and STM8A.
[Microcontroller]
STM8S main clock switching (using HSE clock source)
The clock switching method used is manual switching. The clock switching is performed in the interrupt, and then the switched main clock is output to the CLK_CCO port. Clock switching flow chart (manual switching flow chart): Clock Tree: Register version: unsigned char i=255;  PD_DDR_DDR0=1; //Configure PD0 to
[Microcontroller]
STM8S main clock switching (using HSE clock source)
stm8s development (VII) Use of SPI: SPI host communication!
The previous articles introduced UART serial port, address: http://blog.csdn.net/devintt/article/details/52512457 This time, let’s talk about another commonly used serial port: SPI communication Popular Science SPI: It is a high-speed, full-duplex, synchronous communication bus, and only occupies four lines on the c
[Microcontroller]
stm8s development (VII) Use of SPI: SPI host communication!
STM8S serial port download
Note: Before using UART to burn the program, you need to enable the chip's BootLoader first. Serial port download software found by myself, download link: https://download.csdn.net/download/u013581207/11173125 Or go to the official website to download. The configuration interface is as follows: Parity: verification
[Microcontroller]
STM8S serial port download
Use of STM8S timer
After looking at some resources online, I found none of them very useful, so I decided to summarize and record some simple and practical methods of using timers. Environment: STM8SF103, emulator: STLINK TIM4 is an 8-bit timer with a maximum division frequency of 128. The clock source of this timer is the system clock
[Microcontroller]
STM8S (105K4) User Notes - Configuration of active stop mode and AWU wake-up
Programmable power management provided by STM8S Wait mode: Entered by WFI instruction. In this mode, the CPU will stop running, but the peripherals and interrupt controller will still keep running. In this mode, power consumption can be further reduced by gating peripheral clocks, reducing CPU clock frequency, and
[Microcontroller]
STM8S (105K4) User Notes - Configuration of active stop mode and AWU wake-up
STM32 Note 9: Interrupt it to do things for me, EXIT (external I/O interrupt) application
a)               Purpose: Similar to serial port input, IO input without interrupts is also inefficient, and button events can be inserted through EXTI. This section is related to EXTI interrupts. b)               Initialization function definition: void EXTI_Configuration(void); //Define IO interrupt initialization
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号