Infrared Radiation

Infrared Radiation project describe

(IR==Infrared Radiation )

Chapter 1

Infrared Radiation transmit hardware

Remark:D1 is Infrared Radiation diode

Chapter 2

Infrared Radiation transmit program

#include<reg52.h>

sbit ir=P3^5;//IR DATA 

sbit hz=P3^4;//38KH

unsigned int count, set_count;    

bit keyflag 

unsigned char irdata,ircode,temp;//---------------------------------------------------------------------------

void delay(unsigned int z) //delay 1ms

unsigned char x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--); 

//---------------------------------------------------------------------------

void keyscan()                

P1=0xfe;

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

delay(5);

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

temp=P1;

    switch(temp)

{

case 0xee:

                                {   

                                     keyflag=1;

                                     irdata=0x01;  

                                 }

                     break;

                                 

case 0xde:

                                {

                                    keyflag=1;

                                    irdata=0x02;   

                                }    

break;

                            case 0xbe:

                                {

                                     keyflag=1;  

                                     irdata=0x03;   

                                }

break;

case 0x7e:

                                {

                                     keyflag=1;  

                                     irdata=0x04;   

                                }

break;

}

while(temp!=0xf0)

{

temp=P1;

temp=temp&0xf0;

}

}

}

        

P1=0xfd;

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

delay(5);

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

temp=P1;

switch(temp)

{

case 0xed:{

                                     keyflag=1;  

                                     irdata=0x05;   

                                 }

break;

case 0xdd:{

                                     keyflag=1;  

                                     irdata=0x06;   

                                 }

break;

case 0xbd:{

                                     keyflag=1;  

                                     irdata=0x07;   

                                 }

break;

case 0x7d:{

                                     keyflag=1;  

                                     irdata=0x08;   

                                 }

break;

}

while(temp!=0xf0)

{

temp=P1;

temp=temp&0xf0;

}

}

}

P1=0xfb;

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

delay(5);

temp=P1;

temp=temp&0xf0;

while(temp!=0xf0)

{

temp=P1;

switch(temp)

{

case 0xeb:{

                                     keyflag=1;  

                                     irdata=0x09;   

                                 }

break;

case 0xdb:{

                                     keyflag=1;  

                                     irdata=0x00;   

                                 }

break;

case 0xbb:{

                                     keyflag=1;  

                                     irdata=0x0a;   

                                 }

break;

case 0x7b:{

                                     keyflag=1;  

                                     irdata=0x0b;   

                                 }

break;

}

while(temp!=0xf0)

{

temp=P1;

temp=temp&0xf0;

}

}

}

}

//---------------------------------------------------------------------------

void ir_sendbyte()    //transmit 1 byte irdata

unsigned char i; 

for(i=0;i<8;i++)    //transmit 8 bit irdata

          set_count=1;//transmit 0.56ms high level

          ir=1;     //open ir transmit 

          count=0;     //interrupt count clean

          TR0=1;      //open timer0

          while(count<set_count); //delay transmit end

          TR0=0; //close timer0

    

           if(ircode&0x01)

           set_count=3; //1 is 1.68ms low level 

           else set_count=1;    //0 is 0.56ms low level 

           ir=0; 

           count=0; //interrupt count clean

           TR0=1; //open timer0

           while(count<set_count); //delay transmit end

           TR0=0; //close timer0

           ircode=ircode>>1; //irdata move to right    

//---------------------------------------------------------------------------

void ir_send() //transmit Infrared Radiation data

            set_count=16;//transmit start coding 9ms high level 

            ir=1;

            count=0;    //clean count 

            TR0=1; 

            while(count<set_count); 

            TR0=0; 

            set_count=8;//transmit start coding 4.5ms low level

            ir=0;

            count=0; 

            TR0=1; 

            while(count<set_count); //delay transmit end

            TR0=0; 

            ircode=irdata;   //transmit 8 bit ir data

            ir_sendbyte(); 

            ircode=~irdata; //transmit 8 bit ir !data 

            ir_sendbyte(); 

  

//---------------------------------------------------------------------------

void timer0_init()    //timer0 initialization

   TMOD=0x11;

   TH0=(65535-560)/256;

   TL0=(65535-560)%256;  

   EA=1;    

   ET0=1;

//---------------------------------------------------------------------------

void timer1_init()    //timer0 initialization 

       

TH1=(65535-11)/256;  

        TL1=(65535-11)%256;       

        ET1=1;    

        TR1=1; 

          

void main() 

    timer0_init(); 

    timer1_init()

    count=0;     //clean 0 interrupt count  

    while(1) 

            { 

            keyscan();     //keyscan      

              if(keyflag)  //Whether key press down 

               { 

                    delay(10); //delay

                    ir_send(); //transmit it data 

                    delay(500);   //delay

                    keyflag=0;    //key flag bit clean 

                    delay(100);    //delay

               }  

            }

}   

//---------------------------------------------------------------------------

void timer0() interrupt 1      //timer 0

{

        TH0=(65535-560)/256;     

        TL0=(65535-560)%256;

        count++; 

void timer1() interrupt 3       //timer 1  //38khz frequence product

{

        TH1=(65535-11)/256;   

        TL1=(65535-11)%256;

        hz=~hz; 

Chapter 3

Infrared Radiation receive hardware

Remark:

U13 is stc90c516rd+

U11 ia el817

U225N120 is u25n120

D1 is IR receive diode

Chapter 4

Infrared Radiation receive program

#include <REGX52.H>

#define uint unsigned int    

#define uchar unsigned char

sbit hw_in=P3^3;

sbit id = P3^7;

sbit cl =P3^5;

sbit testcurrent=P1^7;

uchar time=0;

uchar period=10;

uchar high;

uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,

                     0x6d,0x7d,0x07,0x7f,0x6f,

 0x77,0x7c,0x39,0x5e,0x79,

 0x71};

uchar irdate[2];

uchar temp=0;

void delay(unsigned char num)  //delay  

{

 

while(num)

num--;

}

void main()

{

testcurrent=1;

P2=7;

EA=1; //open interrupt

EX1=1;   //open external interrupt 1

IT1=1; //set negative edge trigger of open external interrupt 1 

         

TMOD=0X01; //work mode 1

TH0=(65536-2000)/256;

TL0=(65536-2000)%256;

ET0=1;

while(1) //cycle display

{  

  

  switch(temp)

{

case 0x00:

//high=0;

id=0;

break;

case 0x01:

high=1;

break;

case 0x02:

high=2;

break;

case 0x03:

high=3;

break;

case 0x04:

high=4;

break;

case 0x05:

high=5;

break;

case 0x06:

high=6;

break;

case 0x07:

high=7;

break;

case 0x08:

high=8;

break;

case 0x09:

high=9;

break;

default:

break;

}

TR0=1;

EX1=1;

}

}

timer0() interrupt 1 using 1

{

time++;

TH0=(65536-2000)/256;

TL0=(65536-2000)%256;

if(time<high)

{

cl=0;

delay(1);

id=1;

}

else if(time!=period)

{

id=0;

delay(1);

cl=1;

}

else if (time==period)

{

time=0;

cl=0;

delay(1);

id=1;

}

}

 

void ir(void)   interrupt 2 using 2     //external interrupt 1 serve program

{

uchar i,j,tmp;

EX1=0;    //close interrupt1

delay(100);

if(hw_in)   //   

return;

 

while(!hw_in); //delay guide 9MS low level end

while(hw_in);  //delay guide 4.5MS high level end 

 

for(i=0;i<2;i++)

{

   tmp=0;

   for(j=0;j<8;j++)

   { 

     tmp>>=1;

 delay(30);       

     while(!hw_in); //delay irdata 0.56MS low level end

 delay(140);      

 //delay(2400);

// temp=5;

 if(hw_in)

 {

      tmp+=0x80;  

 

              delay(122);    

  }

         

   }

     irdate[i]=tmp;

                            }

if(irdate[0]==~irdate[1]) 

   {

      switch(irdate[0])

  {

             case 0x00: temp=0;P0=table[temp];break;//0  

 case 0x01: temp=1;P0=table[temp];break;//1

 case 0x02: temp=2;P0=table[temp];break;//2

 case 0x03: temp=3;P0=table[temp];break;//3

 case 0x04: temp=4;P0=table[temp];break;//4

 case 0x05: temp=5;P0=table[temp];break;//5

 case 0x06: temp=6;P0=table[temp];break;//6

 case 0x07: temp=7;P0=table[temp];break;//7

 case 0x08: temp=8;P0=table[temp];break;//8

 case 0x09: temp=9;P0=table[temp];break;//9

             default:P0=0xff; break;

 }

   }

}

Charter 5

Video 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值