// Copyright 2006 Yamane Akira //ICC-AVR application builder : 2005/09/06 22:33:17 // Target : M48 // Crystal: 8.0000Mhz #include #include unsigned char vl,vh,j,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: 496.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; ADMUX = 0x40 | (ch_bit && 0x01); j++; } //ADC initialize // Conversion time: 104uS void adc_init(void) { ADCSRA = 0x00; //disable adc ADMUX = 0x40; //select adc input 0 right adjust ACSR = 0x80; ADCSRB = 0x03; DIDR0=0x01; ADCSRA = 0xAE; } #pragma interrupt_handler adc_isr:22 void adc_isr(void) { vl=ADCL; //Read 8 low bits first (important) vh=ADCH; //read 82high bits PORTB = vl; PORTD = vh | (ch_bit << 4); } //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(); 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 //all peripherals are now initialized } // void main(void) { init_devices(); ch_bit=0x01; j=0; while(1) ; }