All pastes #1723338 Raw Edit

Someone

public text v1 · immutable
#1723338 ·published 2009-12-22 05:28 UTC
rendered paste body
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>

#ifndef F_CPU
#define F_CPU 8000000
#endif


//SIMAVR
#include "avr_mcu_section.h"
AVR_MCU(F_CPU, "atmega48");
/*
const struct avr_mmcu_vcd_trace_t _mytrace[]  _MMCU_ = {
	{ AVR_MCU_VCD_SYMBOL("TCNT1"), .what = (void*)&TCNT1, },
	{ AVR_MCU_VCD_SYMBOL("OCR1A"), .what = (void*)&OCR1A, },
};
*/


void pwminit (void) {
		// disable PWM while configuring it
		TCCR1A = 0;

		// used for TOP, makes for 50 hz PWM = (8,000,000 / (8 * 50)) - 1
		ICR1 = 19999;

		// servo pins outputs
		DDRB = _BV(PB1) | _BV(PB2);

		// set up counter 1 (16 bit) to act as a dual channel PWM generator
		// comparator mode = non-inverting, use ICR1 as TOP and have a prescale of 8.
		TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
		TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);
}


int main(void)
{
	pwminit();
    sei();
    
    OCR1A = 1000;
    _delay_ms(100);
    OCR1A = 2000;
    _delay_ms(100);
    OCR1A = 1500;
    _delay_ms(100);
    
	cli();
	sleep_mode();
}