Код: Выделить всё
#define IRLED LATB.B2
int addd[] = {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}; // двухбайтовый адрес
int comm[] = {1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1}; // прямая и инверсная команда
void main() {
ANCON0 = 0xFF;
ANCON1 = 0xFF;
PLLEN_Bit = 1;
TRISB = 0x00; // Set all pins at the PORTB to output
TRISC = 0x04; // Set all pins at the PORTC, except B2, to output. Set B2 to input
if(если кнопка нажата) { // здесь сократил. В общем условие такого, что если мы нажали кнопку и не отпустили, то тело условия выполняется один раз и ничего не делает больше.
out_one(9000);
out_zero(4500);
for(j=0;j<16;++j) {
if(addd[j] == 0) {
out_one(560);
out_zero(1120-560);
} else if(addd[j] == 1) {
out_one(560);
out_zero(2250-560);
}
}
for(j=0;j<16;++j) {
if(comm[j] == 0) {
out_one(560);
out_zero(1120-560);
} else if(comm[j] == 1) {
out_one(560);
out_zero(2250-560);
}
}
out_one(560);
}
}
void out_one(int duration_us) {
int currTime = 0;
while(currTime < duration_us) {
IRLED = 1;
Delay_us(13); // 13 us ~ полупериод 38 кГц
IRLED = 0;
Delay_us(13);
currTime += (2 * 13);
}
IRLED = 0;
}
void out_zero(int duration_us) {
int currTime = 0;
while(currTime < duration_us) {
IRLED = 0;
Delay_us(13);
currTime += 13;
}
}
