просто нет времени разбирасть и вспоминать...
буду очень признателен
Код: Выделить всё
//ICC-AVR application builder : 05.04.2007 14:46:26
// Target : ATmega8
// Crystal: 4.0000Mhz
#include <iom8v>
#include <macros>
void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:256
// desired value: 347Hz
// actual value: 347,222Hz (0,1%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0xD3; //set count
TCCR0 = 0x04; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0xD3; //reload counter value
}
//TIMER1 initialize - prescale:8
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 455Hz
// actual value: 455,373Hz (0,1%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFB; //setup
TCNT1L = 0xB6;
OCR1AH = 0x04;
OCR1AL = 0x4A;
OCR1BH = 0x04;
OCR1BL = 0x4A;
ICR1H = 0x04;
ICR1L = 0x4A;
TCCR1A = 0x00;
TCCR1B = 0x02; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xFB; //reload counter high value
TCNT1L = 0xB6; //reload counter low value
}
//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();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x05; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
init_devices();
//insert your functional code here...
}