qestin
Üye
- Katılım
- 19 May 2019
- Mesajlar
- 3
- Puanları
- 1
- Yaş
- 34
microC kullanarak başka bir kaynak üzerinde oynamalar yaparak kendi pic ime uyarladığım kodu çalıştıramadım. Nerede hata yaptığımı bulabilirseniz çok sevinirim. Bu arada kumandadan gelen kodu arduino unu ile okudum. Bastığım tuş " 807F48B7 " kodunu gönderiyor. switch case de olasılık denedim ama olmadı Bu arada programın başındaki kodlar çalışıyor. ilk led 1.5 sn yanıp sönüyor.
Kod:
#define IrPin RA0_bit
#define LedPin RB0_bit
char text[5];
unsigned long ir_code;
unsigned int address;
unsigned short command, inv_command;
short nec_remote_read() {
unsigned long count = 0, i;
// 9ms kontrol islemi
while((IrPin == 0)&&(count<=180)) {
count++;
delay_us(50);
}
if((count > 179)||(count < 120))
return 0;
count = 0;
// 4,5ms kontrol islemi
while((IrPin == 0)&&(count <= 90)) {
count++;
delay_us(50);
}
if((count > 89)||(count < 40))
return 0;
//32 bit kod okuma islemi baslıyor
for(i=0; i < 32; i++) {
count = 0;
while((IrPin == 0)&&(count <= 23)) {
count++;
delay_us(50);
}
if((count > 22) || (count < 4))
return 0;
count = 0;
while(IrPin && (count <= 45)) {
count++;
delay_us(50);
}
if((count > 44) || (count < 8))
return 0;
if(count > 21)
ir_code |= 1ul << (31 - i);
else
ir_code &= (1ul << (31 - i));
}
return 1;
}
void main() {
TRISA = 0x01;
TRISB = 0x00;
PORTA = 0;
PORTB = 0;
LedPin = 1;
delay_ms(1500);
LedPin = 0;
delay_ms(1000);
while (1) { //Loop executed infinite times
//while (IR_PIN); //Wait until IR pin falls
if (nec_remote_read()) {
address = ir_code >> 16;
command = ir_code >> 8;
inv_command = ir_code;
IntToHex(address, text); // Save address in string text with hex format
//Lcd_Out(1, 11, text); // Display address
ByteToHex(command, text); // Save command in string text with hex format
//Lcd_Out(2, 7, text); // Display command
ByteToHex(inv_command, text); // Save inverted command in string text with hex format
//Lcd_Out(2, 15, text); // Display inverted command
switch (command) {
case 0x807F:
LedPin = 1;
delay_ms(5000);
LedPin = 0;
break;
break;
case 0x48:
LedPin = 1;
delay_ms(1000);
LedPin = 0;
break;
case 0xB7:
LedPin = 1;
delay_ms(1000);
LedPin = 0;
break;
case 0x7F:
LedPin = 1;
delay_ms(1000);
LedPin = 0;
break;
case 0x80:
LedPin = 1;
delay_ms(1000);
LedPin = 0;
break;
}
}
}
}