-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAIN.c
More file actions
98 lines (73 loc) · 1.98 KB
/
MAIN.c
File metadata and controls
98 lines (73 loc) · 1.98 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* MAIN.c
*
* Bradley University
* ECE 205
* Project 7
*/
/***********************************************
Header Files
************************************************/
#include "MAIN.h"
/***********************************************
Global Variables
************************************************/
volatile uint8_t int_timer = 0;
volatile uint8_t CH1 = 0;
volatile uint8_t CH2 = 0;
/**********************************************
Main
***********************************************/
int main(void)
{
// 16-bit static variable declaration
static uint8_t time_srv = 0; //timer service flags for scheduling
// 16-bit variable declaration
uint8_t temp = 0;
// 8-bit variable declaration
uint8_t prev_key = 0;
uint8_t key = 0;
//User Defined Initialization Processes
init_ports();
init_timers();
sei(); //enable global interrupts
/************************ MAIN WHILE LOOP ************************/
while(1){
temp = time_srv^int_timer;
if(temp & 0x01){ //service every 4.0 [ms]
time_srv = time_srv ^ 0x01;
key = Debounce(); //Debounce all 4 buttons
if (key != prev_key){ //stop auto repeat
//************* PWM Pair 1 **************//
if((key & 0xC0) != 0){ //ignore if both buttons are pressed
if(key == 0x7F){ // (x)%
if(CH1 < 20){
CH1 = CH1 + 1;
//LED_PORT ^= (1 << 7);
}
}
else if(key == 0xBF){ // (100-x)%
if(CH1 > 0){
CH1 = CH1 - 1;
//LED_PORT ^= (1 << 6);
}
}
}
//************* PWM Pair 2 **************//
if((key & 0x30) != 0){ //ignore if both buttons are pressed
if(key == 0xDF){ // (x)%
if(CH2 < 20){
CH2 = CH2 + 1;
}
}
else if(key == 0xEF){ // (100-x)%
if(CH2 > 0){
CH2 = CH2 - 1;
}
}
}
prev_key = key;
}//if
}//if
}//while
}// END MAIN