Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 9.6 MHz, built in resonator
- #define F_CPU 9600000
- #define LED PB1
- #define LED1 PB0
- #include <avr/io.h>
- #include <util/delay.h>
- void pwm_setup (void)
- {
- // Set Timer 0 prescaler to clock/8.
- // At 9.6 MHz this is 1.2 MHz.
- TCCR0B |= (1 << CS01);
- // Set to 'Fast PWM' mode
- TCCR0A |= (1 << WGM01) | (1 << WGM00);
- // Clear OC0B output on compare match, upwards counting.
- TCCR0A |= (1 << COM0B1);
- }
- void pwm_write (int val)
- {
- OCR0B = val;
- }
- int main (void)
- {
- int pwm = 0;
- int count = 0;
- // LED is an output.
- DDRB |= (1 << LED);
- DDRB |= (1 << LED1);
- pwm_setup();
- while (1) {
- // Get the ADC value
- //adc_in = adc_read();
- // Now write it to the PWM counter
- pwm_write(pwm);
- _delay_ms(5);
- if (pwm==255)
- {
- count = 1;
- }
- if (pwm==0)
- {
- count = 0;
- }
- if (count == 0)
- {
- pwm++;
- }
- if (count == 1)
- {
- pwm--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment