-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_led_blink_async.c
42 lines (33 loc) · 978 Bytes
/
4_led_blink_async.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
#include <avr/io.h>
#include <util/delay.h>
#define LED1_PIN PD0
#define LED2_PIN PD1
int main(void) {
DDRD |= (1 << LED1_PIN) | (1 << LED2_PIN);
const uint16_t period_led1 = 3000;
const uint16_t period_led2 = 2000;
uint16_t time_led1 = 0; // Время для первого светодиода
uint16_t time_led2 = 0; // Время для второго светодиода
while (1) {
_delay_ms(10);
time_led1 += 10;
time_led2 += 10;
if (time_led1 >= period_led1) {
time_led1 = 0;
}
if (time_led1 < (period_led1 / 2)) {
PORTD |= (1 << LED1_PIN);
} else {
PORTD &= ~(1 << LED1_PIN);
}
if (time_led2 >= period_led2) {
time_led2 = 0;
}
if (time_led2 < (period_led2 / 2)) {
PORTD |= (1 << LED2_PIN);
} else {
PORTD &= ~(1 << LED2_PIN);
}
}
return 0;
}