The microcontroller source program is as follows:
/*******************************************************************
Work: Infrared Emission
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; ……………………
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Microcomputer Principles and Interface Design
- What is the relationship between the machine cycle and clock cycle of RH850?
- The highest increase is 30%, 10 IC manufacturers including ST, MediaTek, and ON Semiconductor have increased prices!
- Inductor Current Measurement in Switching Power Supplies
- [HC32F460 Development Board Review] 07. Hardware I2C to implement EEPROM read and write operations
- Xunwei i.MX6ULL terminator process basic exec function family
- LLAKG: Arduino automatic watering system (Episode 1: System concept and function introduction)
- Accelerating the design of electric masks
- Error of PMSM sliding mode observer?
- Please recommend a good digital circuit simulation software