-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFramework2.c
More file actions
75 lines (61 loc) · 1.78 KB
/
Framework2.c
File metadata and controls
75 lines (61 loc) · 1.78 KB
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
#include <MK64F12.h>
/*
Main program: entry point
*/
#ifndef F_CPU
#define F_CPU 120000000UL
#endif
//Sets Up Green LED
void setUpGreenLED(){
SIM->SCGC5 |= (1 << 13); //Enable clock to port 26
PORTE->PCR[26] |= PORT_PCR_MUX(001); //Set up port 26 for output
PTE->PDDR |= (1 << 26); //set direction for green LED
PTE->PSOR |= (1 << 26); //set off at default
}
//Toggles Green LED
void toggleGreenLED() {
PTE->PTOR |= (1 << 26); //Toggle green LED
}
//Sets Up Blue LED
void setUpBlueLED(){
SIM->SCGC5 |= (1 << 10); //Enable clock to port 21
PORTB->PCR[21] |= PORT_PCR_MUX(001); //Set up port 21 for output
PTB->PDDR |= (1 << 21); //set direction for blue LED
PTB->PSOR |= (1 << 21); //set off at default
}
//Toggles Blue LED
void toggleBlueLED() {
PTB->PTOR |= (1 << 21); //Toggle blue LED
}
//Enables PIT Timer for Green LED
void enableTimer(){
SIM->SCGC6 = SIM_SCGC6_PIT_MASK; // Enable clock to PIT module
PIT->MCR =0x00; // Allows me to turn timer on
PIT->CHANNEL[0].LDVAL = 45000000/3; // Set load value of zeroth PIT NOTE PIT has 50Mhz Clock so this is 1 sec
PIT->CHANNEL[0].TCTRL |= (1 << 1); // Enable Interrupts
PIT->CHANNEL[0].TCTRL |= (1 << 0); // Start timer
}
int main (void)
{
NVIC_EnableIRQ(PIT0_IRQn); /* enable PIT0 Interrupts (for part 2) */
setUpGreenLED();
setUpBlueLED();
enableTimer();
/* your code goes here */
int k; //for loop variable
while(1) {
for(k = 0; k < F_CPU/(8*10); ++k){ //there are about 8 instructions in a for loop iterations therefore divide by 8
}
//toggleBlueLED();
}
}
/*
PIT Interrupt Handler
*/
void PIT0_IRQHandler(void)
{
/* code goes here */
PIT->CHANNEL[0].TFLG = 1;
toggleGreenLED();
PIT->CHANNEL[0].TCTRL |=(1 << 0);
}