-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirmware.c
More file actions
62 lines (50 loc) · 1.25 KB
/
firmware.c
File metadata and controls
62 lines (50 loc) · 1.25 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
#define F_CPU 16e6
#include <avr/io.h>
// Port B
#define LED 0b00100000
// Port C
#define POS 0b00000001
#define NEG 0b00001000
static const char *const data = "~PN\r";
static void transmit(unsigned long delay)
{
register char c;
for (const char *ptr = data; *ptr; ptr++) {
c = *ptr;
// start bit
PORTC = POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 0)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 1)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 2)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 3)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 4)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 5)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 6)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
PORTC = (c & (1 << 7)) ? NEG : POS;
__builtin_avr_delay_cycles(delay);
// two stop bits for good measure
PORTC = NEG;
__builtin_avr_delay_cycles(delay);
__builtin_avr_delay_cycles(delay);
}
}
int main(void)
{
DDRB = LED;
DDRC = POS | NEG;
PORTC = NEG;
while (1) {
PORTB = LED;
transmit(F_CPU / 9600);
PORTB = 0;
__builtin_avr_delay_cycles(F_CPU * 2);
}
}