-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
103 lines (79 loc) · 1.52 KB
/
main.c
File metadata and controls
103 lines (79 loc) · 1.52 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
99
100
101
102
103
/*
* main.c
*
* Created on: Aug 27, 2023
* Author: Manwil
*/
#include "DIO.h"
#include "INTERRUPT.h"
#include "LCD.h"
#include "TIMER.h"
u16 counter=0;
u8 last_stop=0;
u8 minutes = 0;
u8 seconds = 0;
u8 last_sec_screen=10;
u8 last_min_screen=10;
u8 state=0;
void main(){
INTERRUPT_GIE_ENABLE();
LCD_INIT();
DIO_u8_SET_PIN(PORTD, PIN2, INPUT);
DIO_u8_SET_PIN(PORTD, PIN3, INPUT);
DIO_u8_SET_PIN(PORTB, PIN2, INPUT);
DIO_u8_WRITE_PIN(PORTD, PIN2, HIGH);
DIO_u8_WRITE_PIN(PORTD, PIN3, HIGH);
DIO_u8_WRITE_PIN(PORTB, PIN2, HIGH);
INTERRUPT_INIT(INTERRUPT_PIN_0 , MOOD_FALL);
INTERRUPT_INIT(INTERRUPT_PIN_1 , MOOD_FALL);
INTERRUPT_INIT(INTERRUPT_PIN_2 , MOOD_FALL);
while(1){
if(counter == 4000){
seconds++;
if(seconds ==60){
seconds=0;
minutes++;
}
counter=0;
}
// check for change
if(last_sec_screen != seconds || last_min_screen != minutes){
LCD_CLEAR();
LCD_WRITE_INT(minutes);
LCD_WRITE_STRING(" - ");
LCD_WRITE_INT(seconds);
last_sec_screen=seconds;
last_min_screen=minutes;
}
}
}
// start/resume
ISR(INT0){
TIMER_0_SET_INIT(last_stop);
TIMER_0_SET_COMPARE(250);
TIMER_0_INIT(CTC_0, PRE_8);
state=1;
}
ISR(TIMER_0_COMP){
switch(state){
case 1:
// start / resume
counter++;
break;
default:
break;
}
}
// stop
ISR(INT1){
state=0;
last_stop=TIMER_0_GET_TCNT();
}
// reset
ISR(INT2){
state=0;
last_stop=0;
counter=0;
minutes=0;
seconds=0;
}