// Copyright 2006 Yamane Akira //ICC-AVR application builder : 2005/06/10 13:17:53 // Target : M8 // Crystal: 8.0000Mhz #include #include #include unsigned char i; void port_init(void) { PORTB = 0xFF; DDRB = 0x02; PORTC = 0x7F; //m103 output only DDRC = 0x00; PORTD = 0xFF; DDRD = 0xFF; } //TIMER1 initialize - prescale:1 // WGM: 4) CTC, TOP=OCRnA // desired value: 4MHz // actual value: 4.000MHz (0.0%) void timer1_init(void) { TCCR1B = 0x00; //stop TCNT1H = 0xFF; //setup TCNT1L = 0xFF; OCR1AH = 0x00; OCR1AL = 0x00; OCR1BH = 0x00; OCR1BL = 0x01; ICR1H = 0x00; ICR1L = 0x01; TCCR1A = 0x40; TCCR1B = 0x09; //start Timer } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer1_init(); MCUCR = 0x00; GICR = 0x00; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } void osccal_set(void) { unsigned char Temp; Temp = PINC; if (Temp == 0b00111110) { PORTD = i++; OSCCAL = i; } if (Temp == 0b00111101) { PORTD = i--; OSCCAL = i; } if (Temp == 0b00111011) { EEPROM_WRITE(0x1FF,i); } } void delay() { unsigned char a,b; for (a = 1; a; a++) for (b = 1; b; b++) ; } // void main(void) { init_devices(); //insert your functional code here... EEPROM_READ(0x1FF,i); OSCCAL = i; PORTD = i; while(1) { delay(); osccal_set(); } }