基于单片机的红外发送程序(Infineon--XC866)
时间:11-29
来源:互联网
点击:
本程序适用于Infineon--XC866的单片机,载波为38KHZ,通过P3_0作为发送端口,其中:0由0.56m的高电平和0.56ms的低电平组成,1由0.56的高电平和1.68ms的电平组成。稍加修改可应用于C51。
发送程序如下:
//****************************************************************************// @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// 完整代码下载地址:点这里// 与本程序对应的红外接收程序代码:http://www.51hei.com/mcu/1096.html//****************************************************************************#include "MAIN.H"// USER CODE BEGIN (MAIN_General,2)#include#define uint unsigned int //宏定义#define uchar unsigned char#define HWTx P3_0 //位声明:红外发射管脚 bit HWTx_Out; //红外发射管脚的状态bit Key_Flag,Flag; //分别是:按键按下的标志位,定时器开始的标志位uint Count,Set_Count; //控制定时时间的变量uchar Table_Tx[4]={0x40,0,0,0};//待发送的缓冲区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 ENDvoid 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 GPIOIO_vInit();// Interrupt PriorityIP = 0x00; // load Interrupt Priority RegisterIPH = 0x00; // load Interrupt Priority High RegisterIP1 = 0x00; // load Interrupt Priority 1 RegisterIPH1 = 0x00; // load Interrupt Priority 1 High Register// USER CODE BEGIN (MAIN_Init,3)// USER CODE END// globally enable interruptsEA = 1; } // End of function MAIN_vInit//****************************************************************************// @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) //延时时间约为 1ms*X 晶振为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; //循环变量for(i=0;i<8;i++) //8位数据,顾循环8次{Set_Count=0x002b;//准备发送长达0.56ms(13*43=560us)的方波Flag=1; //置标志位(通过该标志位控制高低电平的转换),因为高电平器件,38K的波形不会改变 Count=0; //清零,准备计数 TR0=1; //启动定时器 while(Count >1;//右移一位,准备发送 }}void Send_Code(){ uchar i=0;Set_Count=690;//准备产生9ms(13*690=9000)的高电平 Flag=1; //置标志位,取反(该标志位控制高低电平的转换)Count=0; //定时器计数TR0=1; //启动定时器while(Count
单片机红外发送程序XC86 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)