blob: a73e7ef9d50514a8bd5e3d9d80698df0607c6378 (
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
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
|
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include "uart.h"
uint8_t t0_ovf_cnt = 0;
uint8_t pb0_thresh = 128;
ISR(TIMER0_OVF_vect) {
cli();
/*TCNT0 = (1<<7);*/ /* Hack-increase Interrupt trigger freq */
t0_ovf_cnt ++;
if ( t0_ovf_cnt >= pb0_thresh )
PORTB &= ~(1<<PINB0);
else
PORTB |= (1<<PINB0);
sei();
}
ISR(TIMER2_OVF_vect) {
cli();
pb0_thresh ++;
sei();
}
int main(void) {
char c;
cli();
/* Pins */
DDRB |= (1<<PINB0);
/* Enable TIMER0 with interrupt, no prescaler */
TCCR0 |= (1<<CS00);
TIMSK |= (1<<TOIE0);
/* Enable TIMER2 with interrupt, Clk divide by 1024 */
/*
TCCR2 |= (7<<CS20);
TIMSK |= (1<<TOIE2);
*/
/* Uart */
uart_init();
/* Go! */
sei();
while(1){
if( uart_getchar(&c) )
continue;
uart_putchar(c);
pb0_thresh = c;
}
return 0;
}
|