Circuit:



Code:



#include<reg51.h> 
sbit ir = P2^0; 
sbit buzzer = P1^0;  
void main() {    
    ir = 1;    
    while(1)     
    {        
        if(ir == 1){        
            buzzer = 0XFF;         
        }        
        else        
        {               
            buzzer = 0X00;         
        }    
    } 
}