blob: cbec6729e7be25fea93ed39f57c001926e966dc0 (
plain)
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
|
#define baud 9600
#define serial_bit_delay 1000000/baud
#define SERIAL_LOW() PORTB &= ~_BV(PB4)
#define SERIAL_HIGH() PORTB |= _BV(PB4)
// write out a byte as software emulated Uart
void serial_putchar(uint8_t byte)
{
uint8_t mask;
SERIAL_LOW(); // signal start bit
_delay_us(serial_bit_delay);
for (mask = 0x01; mask; mask <<= 1) {
if (byte & mask) { // choose bit
SERIAL_HIGH(); // send 1
} else {
SERIAL_LOW(); // send 0
}
_delay_us(serial_bit_delay);
}
SERIAL_HIGH(); //signal end bit
_delay_us(serial_bit_delay);
}
void serial_puts(const char* str)
{
while (*str) {
serial_putchar((uint8_t)*str);
++str;
}
serial_putchar('\r');
serial_putchar('\n');
}
|