-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
123 lines (104 loc) · 4.19 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ***** 0. Documentation Section *****
// main.c for Lab 9
// Runs on LM4F120/TM4C123
// In this lab we are learning functional debugging by dumping
// recorded I/O data into a buffer
// January 15, 2016
// Lab 9
// Jon Valvano and Ramesh Yerraballi
// ***** 1. Pre-processor Directives Section *****
#include "TExaS.h"
#include "tm4c123gh6pm.h"
// ***** 2. Global Declarations Section *****
// FUNCTION PROTOTYPES: Each subroutine defined
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
// ***** 3. Subroutines Section *****
/*
This Lab9 starter project is the same as C9_Debugging example but
includes the connections to the Lab9 grader. You will make three changes.
First, make the LED flash at 10 Hz. In other words, make it turn on for 0.05 seconds,
and then turn off for 0.05 seconds.
Second, make the LED flash if either switch SW1 or SW2 is pressed
(this means flash the LED if either PF4 or PF0 is 0).
Third, record PortF bits 4,1,0 every time the input changes or the output changes.
For example, if your system detects a change in either PF4 or PF0 input,
record PortF bits 4,1,0. If your system causes a change in PF1, record PortF bits 4,1,0.
If both PF4 and PF0 switch are not pressed, the PF1 output should be low.
If either PF4 or PF0 switches is pressed, the output toggles at 10 Hz (±10%).
Information collected in the Data array matches the I/O on PortF.
50 data points are collected only on a change in input or a change in output.
This means no adjacent elements in the array should be equal.
*/
void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
delay = SYSCTL_RCGC2_R; // allow time for clock to start
GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F
GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0
// only PF0 needs to be unlocked, other bits can't be locked
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF
GPIO_PORTF_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0
GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 in, PF3-1 out
GPIO_PORTF_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0
GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4
GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital I/O on PF4-0
}
// Initialize SysTick with busy wait running at bus clock.
void SysTick_Init(void){
NVIC_ST_CTRL_R = 0; // disable SysTick during setup
NVIC_ST_RELOAD_R = 0x00FFFFFF; // maximum reload value
NVIC_ST_CURRENT_R = 0; // any write to current clears it
NVIC_ST_CTRL_R = 0x00000005; // enable SysTick with core clock
}
unsigned long Led;
void Delay(void){unsigned long volatile time;
time = 80000; // 0.1sec
while(time){
time--;
}
}
// first data point is wrong, the other 49 will be correct
unsigned long Time[50];
// you must leave the Data array defined exactly as it is
unsigned long Data[50];
int main(void){
unsigned long i = 0;
TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and set system clock to 16 MHz
PortF_Init(); // initialize PF1 to output
SysTick_Init(); // initialize SysTick, runs at 16 MHz
i = 0; // array index
//last = NVIC_ST_CURRENT_R;
EnableInterrupts(); // enable interrupts for the grader
GPIO_PORTF_DATA_R &= ~0x02;
while(1){
if (( (GPIO_PORTF_DATA_R & 0x10) == 0x00) || (GPIO_PORTF_DATA_R & 0x01) == 0x00 ) {
GPIO_PORTF_DATA_R ^= 0x02;
if(i<50){
Data[i] = GPIO_PORTF_DATA_R & 0x13;
}
i++;
} else {
GPIO_PORTF_DATA_R &= ~0x02;
}
//Led = GPIO_PORTF_DATA_R; // read previous
//Led = Led^0x02; // toggle red LED
//GPIO_PORTF_DATA_R = Led; // output
// if(i<50){
// now = NVIC_ST_CURRENT_R;
// Time[i] = (last-now)&0x00FFFFFF; // 24-bit time difference
// Data[i] = GPIO_PORTF_DATA_R&0x02; // record PF1
// last = now;
// i++;
// }
Delay();
}
}
// Color LED(s) PortF
// dark --- 0
// red R-- 0x02
// blue --B 0x04
// green -G- 0x08
// yellow RG- 0x0A
// sky blue -GB 0x0C
// white RGB 0x0E
// pink R-B 0x06