-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
69 lines (54 loc) · 1.12 KB
/
main.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
// was 8 MHZ is now 16 MHZ – Scope check
#include <avr/io.h>
#include <util/delay.h>
#define CTL_PIN (1<<5)
#define CTL_HI (!(ACSR & (1<<ACO)))
#define BLINK_DELAY_MS 100
void main()
{
// Flash LED once for debug
DDRB |= _BV(DDB5);
PORTB |= _BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);
PORTB &= ~_BV(PORTB5);
CLKPR = 0x80;
CLKPR = 0x0;
ADCSRB &= ~(1<< ACME);
ACSR |= ( 1<< ACBG);
TCCR0A = 0x03;
TCCR0B = 0x09;
OCR0B = 7;
DDRC = CTL_PIN;
while(1){
PORTC = 0;
while (!CTL_HI);
_delay_ms(4.1);
PORTC |= CTL_PIN;
_delay_ms(4.2);
// 280khz burst (scoped at 277khz)
TCCR0A = 0x23;
TCNT0 = 0x0;
OCR0A = 56;
DDRD |= 1<<5;
_delay_ms(1.5);
// 245khz burst (scope at 247khz)
OCR0A = 63;
TCNT0 = 0x0;
_delay_ms(4.6);
// burst off
TCCR0A = 0x03;
DDRD &= ~(1<<5);
// wait for ack pulse
while (CTL_HI);
// kill init pulldown
PORTC &= ~CTL_PIN;
// Just hang around and
// wait for loss-of-signal
while (1) {
while (CTL_HI);
_delay_ms(100);
if (!CTL_HI)
break;
}
}
}