Помогите с компаратором
В Протеусе все нормально симулируется в живой плате не срабатывает прерывание от компаратора.
Фюзы все стандартно, дополнительно уст BODLEVEL1 убрал CKDIV8
Прошиваю прогой Uniprof
Можно ли как-то в пошаговом режиме выполнить прогу на железе и посмотреть что к чему, а то не понял куда модули отладки uniprof писать.
Вот программа.
/*
Chip type :
ATtiny2313
AVR Core Clock frequency: 8,000 MHz
Memory model : Tiny
External RAM size : 0
Data Stack size : 32
************************************************** ***/
#include ‹tiny2313.h›
#include ‹m8_128.h›
#include ‹delay.h›
#include ‹stdlib.h›
#include ‹math.h›
void mkinit(void)
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
/*
// Reset Source checking
if (MCUSR & 1)
{
// Power-on Reset
MCUSR=0;
// Place your code here
}
else if (MCUSR & 2)
{
// External Reset
MCUSR=0;
// Place your code here
}
else if (MCUSR & 4)
{
// Brown-Out Reset
MCUSR=0;
// Place your code here
}
else
{
// Watchdog Reset
MCUSR=0;
// Place your code here
};
*/
// 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=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=0 State2=0 State1=T State0=T
PORTB=0x00;
DDRB=b_0000_1100;
// Port D initialization
// Func6=In Func5=In Func4=Out Func3=In Func2=In Func1=In Func0=In
// State6=0 State5=T State4=0 State3=T State2=1 State1=1 State0=1
PORTD=b_0000_0111;
DDRD=b_0001_0000;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 125,000 kHz
// Clock value: Timer 0 Stopped
// Mode: Fast PWM top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=b_1000_0011;
TCCR0B=b_0000_0011;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 7,8125 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=b_1000_0010;
TCCR1B=b_0001_1101;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0xff;
OCR1AH=0x00;
OCR1AL=200;
OCR1BH=0x00;
OCR1BL=0x00;
// External Interrupt(s) initialization
// INT0: On INT1: On
// INT Mode: Low level
// Interrupt on any change on pins PCINT0-7: Off
GIMSK=b_1100_0000;
MCUCR=0;//b_0000_1001;
EIFR=b_1100_0000;
PCMSK=b_0000_0000;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=b_1000_0000;
// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;
// Analog Comparator initialization
// Analog Comparator: On
// Digital input buffers on AIN0: Off, AIN1: Off
// Interrupt on Output Toggle
// Analog Comparator Input Capture by Timer/Counter 1: On
ACSR=b_0000_1000;
DIDR=b_0000_0011;
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/1024k
// Watchdog Timer interrupt: On
/*
#pragma optsize-
WDTCR=0x39;
WDTCR=0x69;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
*/
// Global enable interrupts
#asm("sei")
};
// Declare your global variables here
unsigned char a=0,b=0,c=1;
// Analog Comparator interrupt service routine
interrupt [ANA_COMP] void ana_comp_isr(void)
{
//if (ACO) {a=1;};
a=1;
}
void motor(void)
{
a=0;
OCR0A=80;
while (a!=1)
{
if (OCR0A‹160) {OCR0A++;} else {a=1;};
delay_ms(10);
}
}
void stop(void)
{
unsigned int i;
OCR0A=0;
for (i=0;i‹40000;i++) {delay_us(10);};
}
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
//delay_us(10);
if (PIND.1==0) {b=1;};
if ((PIND.0==0)&&(c==1)) {b=2;};
if ((PIND.1)&&(PIND.0)) {b=3;};
if ((PIND.1==0)&&(PIND.0==0)) {b=0;};
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
//b=1;
}
// Interrupt TIMER1 OVERFLOV service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
//if (PIND.6) {c=1;} else {c=0;};
//if ((c==0)&&(PIND.4)) {b=3;};
}
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
}
// Watchdog timeout interrupt service routine
interrupt [WDT] void wdt_timeout_isr(void)
{
//WDTCR|=0x40;
// Place your code here
}
void main(void)
{
mkinit();
while (1)
{
switch (b) {
case 1:{motor(); //vverh
while (PIND.0) {};
b=0;
stop();
break;
};
case 2:{PORTD.4=1; //vniz
motor();
b=0;
while (PIND.1) {if (b==3) {goto otkrv;};};
PORTD.4=0;
stop();
break;
};
case 3:{otkrv:; //vverh revers
stop();
PORTD.4=0;
motor();
while (PIND.0) {};
b=0;
stop();
break;
};
//default:
};
};
}
Файл протеуса и codevisionavr в архиве