Hi Brian,
Now tell you the configuration step, actually, it is really very simple, you also can find it in the sample code which I give you .
1. Open PORTC, PORTB gate clock in SIM_SCGC5
Set bit SIM_SCGC5[PTC], SIM_SCGC5[PTB]
2. Configure PTC12 as gpio output, PTB16 as input interrupt pin.
PORTB_PCR16[IRQC] = 1010, ISF flag and Interrupt on falling-edge.
PORTB_PCR16[MUX] = 001, GPIO function
PORTB_PCR16[PE] = 1, internal pullup or pulldown resistor enable
PORTB_PCR16[PS] = 1, internal pullup resistor is enabled
PORTC_PCR12[MUX] = 001, GPIO function
PORTC_PCR12[PE] = 1, internal pullup or pulldown resistor enable
PORTC_PCR12[PS] = 1, internal pullup resistor is enabled
3. Enable IRQ
IRQ is used to the switch input interrupt.
EnableIRQ(PORTB_IRQn);
4. Write the interrupt service code
void BOARD_SW_IRQ_HANDLER(void)
{
/* Clear external interrupt flag. */
GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
/* Change state of button. */
g_ButtonPress = true;
/* Toggle LED. */
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
}
You can try to modify the sample code to meet your board's demand.
Please modify the board.h, the switch interface, and the led interface.
Please try to modify it, and problem, just let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------