First, the header file:
#ifndef _exti_h_#define_exti_h_typedefenumexti_cfg{Zero_down=0x08u,//low-level trigger, internal pull- downRising_down =0x09u,//rising edge trigger, internal pull- downFalling_down =0x0au,//Falling edge trigger, internal pull- downEither_down =0x0bu,//Jump edge trigger, internal pull- downOne_down =0X0CU,//high-level triggering, internal pull- down//pull up and pull down with the highest flagZERO_UP =0x88u,//low-level trigger, internal pull-upRISING_UP =0x89u,//rising edge trigger, internal pull-upFALLING_UP =0x8au,//Falling edge trigger, internal pull-upEITHER_UP =0x8bu,//Jump edge trigger, internal pull-upONE_UP =0X8CU //high-level triggering, internal pull-up} exti_cfg;//External Interrupt InitializationvoidExti_init (Portx, U8 N, exti_cfg);#endif
Second, the source file
#include"Common.h"#include"gpio.h"#include"exti.h"/************************************************************************** function Name: exti_init* Function Description: Exti external GPIO Interrupt Initialization * Parameter description: Portx port number (porta,portb,portc,portd,porte) * N Port Pin * Exti_c FG trigger options and pull-down options * function return: no *************************************************************************/voidExti_init (portx portx, U8 N, exti_cfg cfg) {sim_scgc5|= (Sim_scgc5_porta_mask << portx);//turn on the portx portPort_pcr_reg (Portx[portx], N)= Port_pcr_mux (1) | PORT_PCR_IRQC (CFG &0x7f) | Port_pcr_pe_mask | (CFG &0x80) >>7);//re-use GPIO, determine trigger mode, turn on pull-up or pull-down resistorsGpio_pddr_reg (Gpiox[portx]) &= ~ (1<< N);//Input ModeENABLE_IRQ (Portx + the);//enable port interrupt, Porta's ISR interrupt number is}
Third, summary
This part of the API cannot specify the interrupt function = =, so the temporary shelving is not necessary.
Smart Car Learning (16)--K60 single-chip computer exit external interrupt