// Copyright 2006 Yamane Akira //ICC-AVR // Target : M48 // Crystal: 1.0000Mhz // Fast PWM Example Program // PD6->500uS low Pulse // PD5->300uS low Pulse // PB0->Start of Cycle #include #include void port_init(void) { PORTB = 0xFF; DDRB = 0xFF; PORTC = 0x7F; //m103 output only DDRC = 0x00; PORTD = 0xFF; DDRD = 0x60; } //TIMER0 initialize - prescale:64 // WGM: PWM Fast // desired value: 16mSec // actual value: 16.384mSec (-2.4%) void timer0_init(void) { TCCR0B = 0x00; //stop TCNT0 = 0x01; //set count OCR0A = 0xC1; OCR0B = 0xDB; TCCR0A = 0xA3; // TCCR0B = 0x02; //start timer } #pragma interrupt_handler timer0_ovf_isr:17 void timer0_ovf_isr(void) { PORTB ^=0x01; } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer0_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EIMSK = 0x00; TIMSK0 = 0x01; //timer 0 interrupt sources TIMSK1 = 0x00; //timer 1 interrupt sources TIMSK2 = 0x00; //timer 2 interrupt sources PCMSK0 = 0x00; //pin change mask 0 PCMSK1 = 0x00; //pin change mask 1 PCMSK2 = 0x00; //pin change mask 2 PCICR = 0x00; //pin change enable PRR = 0x00; //power controller SEI(); //re-enable interrupts //all peripherals are now initialized } // void main(void) { init_devices(); while(1) ; }