-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.c
executable file
·86 lines (74 loc) · 2.09 KB
/
led.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
#include "delay.h"
#include "led.h"
#include <string.h>
#define LED_PIN (1 << 1)
#define PORTB (*((volatile unsigned char *)0x25))
#define DDRB (*((volatile unsigned char *)0x24))
const char *Blink_msg;
unsigned int Blink_pos;
enum Blink_state { phase1, phase2 } blink_state;
void led_init() {
DDRB |= LED_PIN; // Set LED pin as output
PORTB &= ~LED_PIN; // Turn off the LED
}
void led_on() {
PORTB |= LED_PIN;
}
void led_off() {
PORTB &= ~LED_PIN;
}
int led_is_on() {
return (PORTB & LED_PIN) ? 1 : 0;
}
void led_set_blink(char *msg) {
Blink_msg = msg;
Blink_pos = 0;
blink_state = phase1;
delay_set(0, 0);
led_off();
}
void led_update() {
switch (blink_state) {
case phase1:
if (delay_isdone(0)) {
switch (Blink_msg[Blink_pos]) {
case '-':
led_on();
delay_set(0, 750);
//delay_set(0,7);
blink_state = phase2;
break;
case '.':
led_on();
delay_set(0, 250);
//delay_set(0,2);
blink_state = phase2;
break;
case ' ':
led_off();
delay_set(0, 1000);
//blink_state = phase2;
break;
default:
led_off();
delay_set(0, 0);
break;
}
}
break;
case phase2:
if (delay_isdone(0)) {
led_off();
delay_set(0, 100);
//delay_set(0, 1);
Blink_pos++;
if (Blink_pos >= strlen(Blink_msg)) {
Blink_pos = 0;
}
blink_state = phase1;
}
break;
default:
break;
}
}