-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample3b.c
55 lines (37 loc) · 860 Bytes
/
example3b.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
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
volatile int adc_value;
ISR(ADC_vect)
{
adc_value = ADC;
adc_value = adc_value*(3000.0/1023.0)+1000;
OCR1A = adc_value;
ADCSRA |= _BV(ADSC);
}
int main(void)
{
DDRD |= (1<<PORTD3)|(1<<PORTD4);
DDRB |= _BV(DDB1);
ADMUX = 0b01000010;
ADCSRA = 0b10001111; //0b10001111
ADCSRB = 0b00000000;
sei();
ADCSRA |= _BV(ADSC);
TCCR1A = 0b10000010;
TCCR1B = 0b00011000;
OCR1A = 0xFF; //change to liking
ICR1 = 39999; //prescalar-->TOP=(16000000/(50*8))-1
TCCR1B |= _BV(CS11);
while(1)
{
for(int adc_value=0;adc_value<4000;adc_value++)
{
OCR1A = OCR1A+adc_value;
}
PORTD |= (1<<PORTD4);
_delay_ms(500);
PORTD &= ~(1<<PORTD4);
_delay_ms(500);
}
}