+/EE445L
embedded systems
git clone https://git.julia.blue/+/EE445L
054ef41
master
1#include "tm4c123gh6pm.h" 2#include <stdint.h> 3 4void (* input_handler )(int alarm ,int tedit ,int up ,int down ); 5 6void init_interrupts () { 7SYSCTL_RCGCGPIO_R |=0x00000002 ; 8GPIO_PORTB_DIR_R &= ~0x0F ;// (c) make PF4 in (built-in button) 9GPIO_PORTB_AFSEL_R &= ~0x0F ;// disable alt funct on PF4 10GPIO_PORTB_DEN_R |=0x0F ;// enable digital I/O on PF4 11GPIO_PORTB_PCTL_R &= ~0x0000FFFF ;// configure PF4 as GPIO 12GPIO_PORTB_AMSEL_R = 0 ;// disable analog functionality on PF 13GPIO_PORTB_PUR_R |=0x0F ;// enable weak pull-up on PF4 14GPIO_PORTB_IS_R &= ~0x0F ;// (d) PF4 is edge-sensitive 15GPIO_PORTB_IBE_R &= ~0x0F ;// PF4 is not both edges 16GPIO_PORTB_IEV_R &= ~0x0F ;// PF4 falling edge event 17GPIO_PORTB_ICR_R = 0x0F ;// (e) clear flag4 18GPIO_PORTB_IM_R |=0x0F ;// (f) arm interrupt on PF4 *** No IME bit as 19// mentioned in Book *** 20NVIC_PRI0_R = (NVIC_PRI0_R & 0xFFFF00FF ) |0x0000A000 ;// (g) priority 5 21NVIC_EN0_R |=0x00000002 ; 22} 23 24void gpio_portb_handler () { 25//GPIO_PORTB_ICR_R = 0x0F; 26 27int alarm = GPIO_PORTB_DATA_R & 0x01 ; 28int tedit = GPIO_PORTB_DATA_R & 0x02 ; 29int up = GPIO_PORTB_DATA_R & 0x04 ; 30int down = GPIO_PORTB_DATA_R & 0x08 ; 31 32input_handler (alarm ,tedit ,up ,down ); 33} 34 35void init_input (void (* handler )(int ,int ,int ,int )) { 36//init_interrupts(); 37SYSCTL_RCGCGPIO_R |=0x00000002 ; 38GPIO_PORTB_DIR_R &= ~0x0F ; 39GPIO_PORTB_DEN_R |=0x0F ; 40GPIO_PORTB_PDR_R |=0x0F ; 41input_handler = handler ; 42}