Single chip infrared transmitting and receiving circuit

Publisher:火星Latest update time:2020-08-21 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The microcontroller source program is as follows:

/*******************************************************************

        Work: Infrared Emission

  Microcontroller: STC89C52RC

    Crystal: 12M

Compilation environment: Keil uVision4 V9.00

*******************************************************************/

//

// Emitting pin (connected to the PNP transistor B)

//PNP transistor e-pole connected to 2Ω resistor, c-pole connected to infrared emitting tube

     

#include

#include

#define uchar unsigned char

#define uint unsigned int


#define SBM 0x80 //Identification code


#define m9 (65536-9000) //about 9mS

#define m4_5 (65536-4500) //about 4.5mS

#define m1_6 (65536-1630) //about 1.65mS

#define m_65 (65536-580) //about 0.65mS

#define m_56 (65536-560) //about 0.56mS

#define m40 (65536-40000) //about 40mS

#define m56 (65536-56000) //56mS

#define m2_25 (65536-2250) //about 2.25mS


sbit IR = P3^6; //Define the emission pin (connected to the base of the PNP transistor)

sbit LED = P3^7; //Transmit indicator light


uchar KEY(void);

void SanZhuan(void);

void ZZ(uchar x);

void Z0(uchar temp);

void TT0(bit BT,uint x);

void YS(uchar time);


/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Function: Main function

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/

void main(void)

{


  TMOD = 0x01; //T0 16-bit working mode

  IR=1; //The transmitting port is normally high level


  while(1)

  {

   SanZhuan();

  }

}

/*******************************************************************

Function: 4×4 matrix keyboard

                           Key-value                    

P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7

│ │ │ │ │ │ │ │ ┃

│ │ │ └────13 14 15 16 ┃   

│ │ └─────────9 10 11 12 ┃   

│ └──────────────5 6 7 8 ┃   

└────────────────────1 2 3 4 ┃  

*******************************************************************/

uchar KEY(void)

{

uchar H,L; //row value, column value

H=0;

L=0;

P1 = 0xf0; //Set the keyboard port row value to 1 and the column value to 0

if(P1!= 0xf0) //Check if a key is pressed, if so, hangval must not be 0x0f

   {

    YS(10); //key debounce, delay 10 milliseconds

    if(P1!=0xf0) //A key is pressed

      {

       H = P1&0xf0; //After pressing the key, get the row flag of the key and assign the row flag to hangval

       P1 = 0x0f; //Flip keyboard interface output

       L = P1&0x0f; //Get the column flag

      }

        return (H+L);

   }

  return 0;

}

/*******************************************************************

Function: Scatter program

Entry parameter: v

//

// 13 14 15 16

// 9 10 11 12

// 5 6 7 8

// 1 2 3 4

*******************************************************************/

void SanZhuan(void)

{

uchar v;

v = KEY();


switch(v)

{

  case 0x77:ZZ(0x01);v=0;break; //" "

  case 0xb7:ZZ(0x02);v=0;break; //" "

  case 0xd7:ZZ(0x03);v=0;break; //" "

  case 0xe7:ZZ(0x04);v=0;break; //" "

  case 0x7b:ZZ(0x05);v=0;break; //" "

  case 0xbb:ZZ(0x06);v=0;break; //" "

  case 0xdb:ZZ(0x07);v=0;break; //" "

  case 0xeb:ZZ(0x08);v=0;break; //" "

  case 0x7d:ZZ(0x09);v=0;break; //" "

  case 0xbd:ZZ(0x10);v=0;break; //" "

  case 0xdd:ZZ(0x11);v=0;break; //" "

  case 0xed:ZZ(0x12);v=0;break; //" "

  case 0x7e:ZZ(0x13);v=0;break; //" "

  case 0xbe:ZZ(0x14);v=0;break; //" "

  case 0xde:ZZ(0x15);v=0;break; //" "

  case 0xee:ZZ(0x16);v=0;break; //" "

  default:v=0;

}

}

/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Function: Send the main program

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/

void ZZ(uchar x)

{

  TT0(1,m9); //High level 9mS

  TT0(0,m4_5); //Low level 4.5mS


  /*┈ Send 4 frames of data┈*/

  Z0(SBM);                                                                                                                                       

  Z0(~SBM);

  Z0(x);

  Z0(~x);


  /*┈┈ End code┈┈*/

  TT0(1,m_65);

  TT0(0,m40);


  /*┈┈ Repeat code┈┈*/

  while(KEY())

   {

        TT0(1,m9);

        TT0(0,m2_25);


        TT0(1,m_56);

        TT0(0,m40);

                TT0(0,m56);

               

                LED = !LED; //Indicator light                                          

    }


   LED = 1;                    


}

/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Function: Single frame sending program

Entry parameters: 1 frame of data

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/

void Z0(uchar temp)

{

  uchar v;

  for (v=0;v<8;v++) //Loop 8 times shift

       {     

                 TT0(1,m_65); //High level 0.65mS         

                         if(temp&0x01) TT0(0,m1_6); //Send the lowest bit

                         else TT0(0,m_56);     

                         temp >>= 1; //Shift right one bit

        }   

}


/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Function: 38KHz pulse transmission + delay program

Entry parameters: (whether to emit pulses, delay of about x (uS))

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/

void TT0(bit BT,uint x)

{

  TH0 = x>>8; // Input T0 initial value

  TL0 = x;

  TF0=0; //clear to 0

  TR0=1; //Start timer 0

  if(BT == 0) while(!TF0); //When BT=0, 38KHz pulse is not emitted and only delay is performed; when BT=1, 38KHz pulse is emitted and delayed;

  else while(1) //38KHz pulse, duty cycle 5:26

         {

                  IR = 0;

                  if(TF0)break;

               if(TF0)break;

                  IR = 1;

                if(TF0)break;

                 if(TF0)break;

……………………


Reference address:Single chip infrared transmitting and receiving circuit

Previous article:Realizing temperature sensor and key-press clock adjustment based on 51 single-chip microcomputer
Next article:51 MCU water tower schematic diagram and source program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号