Есть такой код:
CODE
/*
* main.c
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
//#include <util/delay.h>
#include "sine_table.h"
#define BTN_UP PD0
#define BTN_DOWN PD1
static int16_t step_counter;
uint8_t step;
uint8_t kvadrant;
uint8_t time_delay;
void IOInit(void){
DDRB=(1<<PB3);
PORTD=(1<<BTN_DOWN)|(1<<BTN_UP);
DDRD=(1<<PD4)|(1<<PD3);
}
void Timer1Init(void){
ICR1=0x01FF;
TCCR1A=(1<<COM1A1);
TCCR1B=(1<<WGM13)|(1<<CS11);
TIMSK=(1<<TOV1);
}
ISR(TIMER1_OVF_vect){
switch(kvadrant){
case 1:{
OCR1A=pgm_read_word(pSine+step_counter);
step_counter+=step;
if (step_counter>511) {step_counter-=step; kvadrant=2;}
break;
};
case 2:{
OCR1A=pgm_read_word(pSine+step_counter);
step_counter-=step;
if (step_counter<0) {step_counter+=step; kvadrant=3;}
break;
};
case 3:{
OCR1A=0x1FF-pgm_read_word(pSine+step_counter);
step_counter+=step;
if (step_counter>511) {step_counter-=step; kvadrant=4;}
break;
};
case 4:{
OCR1A=0x1FF-pgm_read_word(pSine+step_counter);
step_counter-=step;
if (step_counter<0) {step_counter+=step; kvadrant=1;}
break;
};
};
};
int main(void){
OCR1A=0x10;
IOInit();
Timer1Init();
sei();
step=20;
step_counter=511;
kvadrant=4;
PORTD=0xFF;
while(1){
cli();
step=10; // в итоговом коде этого нет! (((
sei();
};
return 0;
}
И почему-то, в итоговом коде отсутствует операция step=10 основного цикла. получается так:
CODE
652: 82 bb out 0x12, r24 ; 18
654: f8 94 cli
656: 78 94 sei
658: fd cf rjmp .-6 ; 0x654 <main+0x44>
Отчего такое может быть? В каком месте у меня кривые руки?