السلام عليكم
كود المستقبل
// IR Receiver //
// PIC16F877A * 8MHz //
// November 2012 //
////////////////////////
char address_string[5]; // This string is used to display the address on LCD
char command_string[5]; // This string is used to display the command on LCD
unsigned int count = 0 , temp = 0;
unsigned short i = 0, rec_bit = 0, command = 0, address = 0, Data = 0, Duty_Cycle = 192;
void interrupt(){
count++;
TMR0 = 0;
INTCON.TMR0IF = 0;
}
unsigned int get_mark(){
TMR0 = 0;
count = 0;
while(!PORTB.F4);
return TMR0 + 256*count;
}
unsigned short get_Data(short n){
Data = 0;
for(i = 0;i<n;i++){
temp = get_mark();
if(temp<=700 && temp>=500) rec_bit = 0;
else if(temp<=1300 && temp>=1100) rec_bit = 1;
else{ i--;continue;}
Data += rec_bit << i;
}
return Data;
}
/************************************************** **********/
void main(){
TRISB = 0x10;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0x00;
TRISD = 0x00;
PORTD = 0x00;
OPTION_REG = 0x80;
INTCON = 0xA0;
LCD_Config(&PORTD,2,3,0,7,6,5,4);
LCD_CMD(LCD_CURSOR_OFF);
LCD_CMD(LCD_CLEAR);
LCD_Out(1,4,"Welcome

");
PWM_Init(500);
PWM_Start();
while(1){
PWM_Change_Duty(Duty_Cycle);
command = 0;
address = 0;
temp = get_mark();
if(temp>=2000 && temp<= 3000){
command = get_Data(7);
address = get_Data(5);
if(address==1){
switch(command){
case 0:
PORTB.F0 = ~PORTB.F0;
Duty_Cycle = 255;
break;
case 1:
PORTB.F1 = ~PORTB.F1;
Duty_Cycle = 223;
break;
case 2:
PORTB.F2 = ~PORTB.F2;
Duty_Cycle = 192;
break;
case 3:
PORTB.F3 = ~PORTB.F3;
Duty_Cycle = 128;
break;
default:
break;
}
delay_ms(10);
}
LCD_Out(1,1,"Address : ");
LCD_Out(2,1,"Command : ");
ShortToStr(address,address_string);
LCD_Out(1,11,address_string);
ShortToStr(command,command_string);
LCD_Out(2,11,command_string);
}
}
}