Infrared sending program based on single chip microcomputer (Infineon--XC866)

Publisher:boczsy2018Latest update time:2015-07-27 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
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.

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
 
Keywords:MCU Reference address:Infrared sending program based on single chip microcomputer (Infineon--XC866)

Previous article:Notes on the MCU Car Project
Next article:Design and implementation of a low-noise portable ECG monitor

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号