#include "tm4c123gh6pm.h" #include void (*input_handler)(int alarm, int tedit, int up, int down); void init_interrupts() { SYSCTL_RCGCGPIO_R |= 0x00000002; GPIO_PORTB_DIR_R &= ~0x0F; // (c) make PF4 in (built-in button) GPIO_PORTB_AFSEL_R &= ~0x0F; // disable alt funct on PF4 GPIO_PORTB_DEN_R |= 0x0F; // enable digital I/O on PF4 GPIO_PORTB_PCTL_R &= ~0x0000FFFF; // configure PF4 as GPIO GPIO_PORTB_AMSEL_R = 0; // disable analog functionality on PF GPIO_PORTB_PUR_R |= 0x0F; // enable weak pull-up on PF4 GPIO_PORTB_IS_R &= ~0x0F; // (d) PF4 is edge-sensitive GPIO_PORTB_IBE_R &= ~0x0F; // PF4 is not both edges GPIO_PORTB_IEV_R &= ~0x0F; // PF4 falling edge event GPIO_PORTB_ICR_R = 0x0F; // (e) clear flag4 GPIO_PORTB_IM_R |= 0x0F; // (f) arm interrupt on PF4 *** No IME bit as // mentioned in Book *** NVIC_PRI0_R = (NVIC_PRI0_R & 0xFFFF00FF) | 0x0000A000; // (g) priority 5 NVIC_EN0_R |= 0x00000002; } void gpio_portb_handler() { //GPIO_PORTB_ICR_R = 0x0F; int alarm = GPIO_PORTB_DATA_R & 0x01; int tedit = GPIO_PORTB_DATA_R & 0x02; int up = GPIO_PORTB_DATA_R & 0x04; int down = GPIO_PORTB_DATA_R & 0x08; input_handler(alarm, tedit, up, down); } void init_input(void (*handler)(int, int, int, int)) { //init_interrupts(); SYSCTL_RCGCGPIO_R |= 0x00000002; GPIO_PORTB_DIR_R &= ~0x0F; GPIO_PORTB_DEN_R |= 0x0F; GPIO_PORTB_PDR_R |= 0x0F; input_handler = handler; }