// Copyright 2006 Yamane Akira //ICC-AVR application builder : 2005/09 // Target : M48 // Crystal: 8.0000Mhz #include #include unsigned char vl,vh,ch_bit; void port_init(void) { PORTB = 0xFF; DDRB = 0xFF; PORTC = 0x00; DDRC = 0x00; PORTD = 0xFF; DDRD = 0xFF; } //TIMER0 initialize - prescale:64 // WGM: CTC // desired value: 500uSec // actual value: 504.000uSec (-0.8%) void timer0_init(void) { TCCR0B = 0x00; //stop TCNT0 = 0xFF; //set count TCCR0A = 0x02; OCR0A = 0x3E; TCCR0B = 0x03; //start timer } #pragma interrupt_handler timer0_compa_isr:15 void timer0_compa_isr(void) { ch_bit = ch_bit ^ 0x01; ADMUX = 0x60 | ch_bit; } //ADC initialize // Conversion time: 104uS void adc_init(void) { ADCSRA = 0x00; //disable adc ADMUX = 0x60; //select adc input 0 ACSR = 0x80; ADCSRB = 0x03; DIDR0 = 0x03; ADCSRA = 0xAE; } #pragma interrupt_handler adc_isr:22 void adc_isr(void) { vl=ADCL; //Read 2 low bits first (important) vh=ADCH; //Read 8 high bits if (ch_bit == 0x00) PORTD = ~vh; else PORTB = ~vh; } void init_devices(void) { CLI(); //disable all interrupts port_init(); timer0_init(); adc_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EIMSK = 0x00; TIMSK0 = 0x02; //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 } // void main(void) { init_devices(); ch_bit = 0x01; while(1) ; }