#include <stdio.h>
#include <AT892051.H>
#include<INTRINS.H>
sbit LED=P1^7;
sbit Key=P1^0;
//幀數(shù)據(jù)放數(shù)組Data里
unsigned char counter=0;
unsigned char Data[5]={0x55,0xff,0x00,0xaa,0x0f};
void Transmit(int c1,int c2); //發(fā)射子程序
//
void delay()
{
int i;
for(i=75000;i>0;i--);
}
void scan_key()
{
while(1)
{
if(Key==0)
{
delay();
if(Key==0)
{
counter++;
if(counter>=4)
counter=0;
break;
}
else
LED=0; //沒鍵按下,等待
}
}
}
void send_code()
{
unsigned char j;
Transmit(143,38); //發(fā)射引導(dǎo)碼
//for(i=0;i<4;i++)
//{
for(j=0;j<8;j++) //發(fā)射幀數(shù)據(jù)
{
if((Data[counter]>>j)&1)
Transmit(75,38); //'1'碼
else
Transmit(38,38); //'0'碼
}
Transmit(285,38);
LED=0;
//}
while(Key==0); //等待釋放按鍵
}
//****************************************
main()
{
LED=0;
while(1)
{
scan_key();
send_code();
delay();
delay();
delay();
}
}
//****************************************
void Transmit(int c1,int c2) //c1為高電平寬度
{
unsigned char i; //c2為低電平寬度
LED=0;
do{
LED=0; //產(chǎn)生38kHz載波
for(i=3;i>0;i--); //延時(shí)18us
LED=1;
for(i=5;i>0;i--); //延時(shí)18us
//_nop_();
}while(--c1);
LED=0;
do{
for(i=8;i>0;i--);
}while(--c2);
}





