-
Notifications
You must be signed in to change notification settings - Fork 0
/
Systick_timer_using_interrupt.c
77 lines (54 loc) · 1.73 KB
/
Systick_timer_using_interrupt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 0.Documentation Section
//
// Runs on LM4F120 or TM4C123
// Use the SysTick timer to request interrupts .
// Jonathan Valvano
// November 3, 2013
#include "PLL.h"
#include "tm4c123gh6pm.h"
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void WaitForInterrupt(void); // low power mode
void PortA_Init(void); // start sound output
void SysInit(void); //initialize SysTick timer
void SysLoad(unsigned long period); //Load reload value
int main(void){
PLL_Init();
PortA_Init();
SysInit();
SysLoad(40000);
while(1){
}
// initialize output and interrupts
//EnableInterrupts();
/*Initialize necessary ports and timers here*/
}
// **************Sound_Init*********************
// Initialize SysTick periodic interrupts
// Input: none
// Output: none
void PortA_Init(void){ unsigned long volatile delay;
/*PORT Initialization*/
SYSCTL_RCGC2_R |= 0x01; // Port A clock
delay = SYSCTL_RCGC2_R; // wait 3-5 bus cycles
GPIO_PORTA_DIR_R |= 0x40; // PA6 output
GPIO_PORTA_AFSEL_R &= ~0x40; // not alternative
GPIO_PORTA_AMSEL_R &= ~0x40; // no analog
GPIO_PORTA_PCTL_R &= ~0x0F000000; // bits for PA6
GPIO_PORTA_DEN_R |= 0x40;
}
void SysLoad(unsigned long period){
NVIC_ST_RELOAD_R = period -1;
}
void SysInit(void){
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0; // any write to current clears it
NVIC_SYS_PRI3_R = NVIC_SYS_PRI3_R&0x00FFFFFF; // priority 0
NVIC_ST_CTRL_R = 0x00000007; // enable with core clock and interrupts
}
// Interrupt service routine
//
void SysTick_Handler(void){
GPIO_PORTA_DATA_R ^= 0x40;
/*Your code goes here*/
}