Здравствуйте. Вот моя программа:
Code
#include <tiny2313.h>
int us;
int S_1,S_2,S_3;
int CS_1,CSt_1;
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
TCNT1=0;
us++;
if(us>=2000) //создание периода 20 мс
{
us=0;
};
}
// Declare your global variables here
void main(void)
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0xFF;
// Port D initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000,000 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x02;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x07;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Global enable interrupts
#asm("sei")
S_1=150;
S_2=150;
S_3=150;
while (1)
{
if(us<S_1) //серво №1
{
PORTB.1=1;
}
else
{
PORTB.1=0;
};
if(us<S_2) //серво №2
{
PORTB.2=1;
}
else
{
PORTB.2=0;
};
if(us<S_3) //серво №3
{
PORTB.3=1;
}
else
{
PORTB.3=0;
};
}
}
Здесь используется прерывание по совпадению с регистром А.
А как сделать так что б было ещё и прерывание по совпадению с регистром В?
Пробовал делать вот так
Code
#include <tiny2313.h>
int us;
int S_1,S_2,S_3;
int CS_1,CSt_1;
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
TCNT1=0;
us++;
if(us>=2000) //создание периода 20 мс
{
us=0;
};
}
// Timer1 output compare B interrupt service routine
interrupt [TIM1_COMPB] void timer1_compb_isr(void)
{
TCNT1=0;
CSt_1++;
if(CSt_1>=2000) //создание периода 20 мс
{
CSt_1=0;
};
}
void main(void)
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0xFF;
// Port D initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000,000 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: On
TCCR1A=0x00;
TCCR1B=0x02;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x07;
OCR1BH=0x00;
OCR1BL=0x07;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Global enable interrupts
#asm("sei")
S_1=150;
S_2=150;
S_3=150;
while (1)
{
if(CSt_1<S_1) //серво №1
{
PORTB.1=1;
}
else
{
PORTB.1=0;
};
if(us<S_2) //серво №2
{
PORTB.2=1;
}
else
{
PORTB.2=0;
};
if(us<S_3) //серво №3
{
PORTB.3=1;
}
else
{
PORTB.3=0;
};
}
}
но ничего не получилось:(.