#include
sbit P3_4 = P2^1;
static bit OP; //红外发射管的亮灭
static unsigned int count; //延时计数器
static unsigned int endcount; //中止延时计数
static unsigned char flag; //红外发送标志
char iraddr1; //十六位地址的第一个字节
char iraddr2; //十六位地址的第二个字节
void SendIRdata(char p_irdata);
void delay();
void main(void)
{
count = 0;
flag = 0;
OP = 0;
P3_4 = 0;
EA = 1; //答应CPU中止
TMOD = 0x11; //设定时器0和1为16位形式1
ET0 = 1; //定时器0中止答应
TH0 = 0xFF;
TL0 = 0xE8; //设定时值0为38K 也便是每隔26us中止一次
TR0 = 1;//开端计数
iraddr1=3;
iraddr2=252;
do{
unsigned char i;
delay();
SendIRdata(12);
}while(1);
}
//定时器0中止处理
void timeint(void) interrupt 1
{
TH0=0xFF;
TL0=0xE8; //设定时值为38K 也便是每隔26us中止一次
count++;
if (flag==1)
{
OP=~OP;
}
else
{
OP = 0;
}
P3_4 = OP;
}
void SendIRdata(char p_irdata)
{
int i;
char irdata=p_irdata;
//发送9ms的开始码 //发送4.5ms的成果码 //发送十六位地址的前八位 //先发送0.56ms的38KHZ红外波(即编码中0.56ms的低电平) //中止发送红外信号(即编码中的高电平) irdata=irdata>>1; //发送十六位地址的后八位 if(irdata-(irdata/2)*2) irdata=irdata>>1; //发送八位数据 if(irdata-(irdata/2)*2) irdata=irdata>>1; //发送八位数据的反码 if(irdata-(irdata/2)*2) irdata=irdata>>1; endcount=10; void delay()
endcount=223;
flag=1;
count=0;
do{}while(count
endcount=117;
flag=0;
count=0;
do{}while(count
irdata=iraddr1;
for(i=0;i<8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count
if(irdata-(irdata/2)*2) //判别二进制数个位为1仍是0
{
endcount=41; //1为宽的高电平
}
else
{
endcount=15; //0为窄的高电平
}
flag=0;
count=0;
do{}while(count
}
irdata=iraddr2;
for(i=0;i<8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count
}
irdata=p_irdata;
for(i=0;i<8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count
}
irdata=~p_irdata;
for(i=0;i<8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count
}
flag=1;
count=0;
do{}while(count
}
{
int i,j;
for(i = 0; i < 400; i++){
for(j = 0; j < 200; j++){
}
}
}