This program is suitable for Infineon--XC866 microcontroller, the carrier is 38KHZ, through P3_0 as the sending port, where: 0 is composed of 0.56m high level and 0.56ms low level, 1 is composed of 0.56 high level and 1.68ms level. It can be applied to C51 with slight modification.
Keywords:MCU
Reference address:Infrared sending program based on single chip microcomputer (Infineon--XC866)
The sending procedure is as follows:
//************************************************ ****************************** // @Module Project Settings // @Filename MAIN.C // @Project 20W.dav //------------------------------------------------ ---------------------------- // @Controller Infineon XC866-2FR // // @Compiler Keil // // @Codegenerator 2.0 // // @Description This file contains the Project initialization function. // //------------------------------------------------ ---------------------------- // @Date 2010-11-4 15:54:56 // //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,1) // USER CODE END //************************************************ ****************************** // @Project Includes // Complete code download address: click here // Infrared receiving program code corresponding to this program: http://www.51hei.com/mcu/1096.html //************************************************ ****************************** #include "MAIN.H" // USER CODE BEGIN (MAIN_General,2) #include#define uint unsigned int //macro definition #define uchar unsigned char #define HWTx P3_0 //Bit declaration: infrared transmitter pin bit HWTx_Out; //status of infrared transmitter pin bit Key_Flag,Flag; // respectively: the flag bit of the button pressed, the flag bit of the timer started uint Count, Set_Count; //Variable to control the timing time uchar Table_Tx[4]={0x40,0,0,0}; //Buffer to be sent uchar HWTx_Code,HWTx_data; // USER CODE END //************************************************ ****************************** // @Macros //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,3) // USER CODE END //************************************************ ****************************** // @Defines //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,4) // USER CODE END //************************************************ ****************************** // @Typedefs //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,5) // USER CODE END //************************************************ ****************************** // @Imported Global Variables //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,6) // USER CODE END //************************************************ ****************************** // @Global Variables //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,7) // USER CODE END //************************************************ ****************************** // @External Prototypes //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,8) // USER CODE END //************************************************ ****************************** // @Prototypes Of Local Functions //************************************************ ****************************** // USER CODE BEGIN (MAIN_General,9) // USER CODE END //************************************************ ****************************** // @Function void MAIN_vInit(void) // //------------------------------------------------ ---------------------------- // @Description This function initializes the microcontroller. It is // assumed that the SFRs are in their reset state. // //------------------------------------------------ ---------------------------- // @Returnvalue None // //------------------------------------------------ ---------------------------- // @Parameters None // //------------------------------------------------ ---------------------------- // @Date 2010-11-4 // //************************************************ ****************************** // USER CODE BEGIN (MAIN_Init,1) // USER CODE END void MAIN_vInit(void) { // USER CODE BEGIN (MAIN_Init,2) // USER CODE END /// -------------------------------------------------- -------------------------- /// Configuration of the System Clock: /// -------------------------------------------------- -------------------------- /// - On Chip Osc is Selected /// - PLL Mode, NDIV = 2 /// - input frequency is 10 MHz /// *********************************************** ********************************** /// Note: All peripheral related IO configurations are done in the /// respective peripheral modules (alternate functions selection) /// *********************************************** ********************************** /// Initialization of module 'GPIO' IO_vInit(); // Interrupt Priority IP = 0x00; // load Interrupt Priority Register IPH = 0x00; // load Interrupt Priority High Register IP1 = 0x00; // load Interrupt Priority 1 Register IPH1 = 0x00; // load Interrupt Priority 1 High Register // USER CODE BEGIN (MAIN_Init,3) // USER CODE END // globally enable interrupts EA = 1; } // End of function MAIN_vInit [page] //************************************************ ****************************** // @Function void main(void) // //------------------------------------------------ ---------------------------- // @Description This is the main function. // //------------------------------------------------ ---------------------------- // @Returnvalue None // //------------------------------------------------ ---------------------------- // @Parameters None // //------------------------------------------------ ---------------------------- // @Date 2010-11-4 // //************************************************ ****************************** // USER CODE BEGIN (MAIN_Main,1) void delay(uint z) //delay time is about 1ms*X crystal oscillator is 12M { uint x=0,y=0; for(x=z;x>0;x--) for(y=54;y>0;y--); } void Key_Scan() { uchar Key_Temp=0,i=0; if(P3_1!=1) { delay(10); if(P3_1!=1) { while(!P3_1); Key_Flag=1; for(i=1;i<4;i++) Table_Tx[i]=i+0xaa; } } } void Send_Code8() { uchar i=0; //loop variable for(i=0;i<8;i++) //8-bit data, loop 8 times { Set_Count=0x002b; //Prepare to send a square wave of 0.56ms (13*43=560us) Flag = 1; //Set the flag bit (the flag bit is used to control the conversion of high and low levels), Because of the high level device, the 38K waveform will not change Count=0; //Clear, ready to count TR0=1; //Start the timer while(Count >1; //Move right one bit, ready to send } } void Send_Code() { uchar i=0; Set_Count=690; //Prepare to generate a high level of 9ms (13*690=9000) Flag = 1; // Set the flag bit and invert it (this flag bit controls the conversion of high and low levels) Count=0; //Timer count TR0=1; //Start the timer while(Count
Previous article:Notes on the MCU Car Project
Next article:Design and implementation of a low-noise portable ECG monitor
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- 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)
Guess you like
- Please tell me, how to make a dual power automatic switching circuit?
- Decimal to hexadecimal C language function
- MSP432E401Y SimpleLink Ethernet Microcontroller
- [AB32VG1 Development Board Review] Getting to Know the Development Board
- Simple driver for 64Mb PSRAM
- How to tell how many layers a PCB has
- [Sipeed LicheeRV 86 Panel Review] II. GPIO pins are brought out, RGB tri-color LED flashes
- Showing off the LTC3588 Energy Harvesting Development Board
- [LSM6DSOX finite state machine routine learning 2]--How to use finite state machine programming
- FPGA Implementation of DMA Transfer Mode of PCI Interface