用单片机矩阵键盘发射用户码数据码 现在是按住不放连续循环发射 怎么改成按住只发射一次 用这个程序发射红米手机发射解出来的码控制机顶盒为什么不能控制
#include<reg52.h>//////////// 12c5a60s2 晶振12M
static bit OP;
//#define uint unsigned int
#define uchar unsigned char
uchar qishiok,count,key,flag,temp1;
uchar xinhaook,ding,qishiflag,temp2;
uchar temp;endcount,temp3,temp4;
uchar kaiok;
//int k01=0,k02=0,k03=0,k04=0,k05=0,k06=0,k07=0,k08=0;
//sbit key01=P1^7;
//sbit key02=P1^6;
//sbit key03=P1^5;
//sbit key04=P1^4;
//sbit key05=P1^3;
//sbit key06=P1^2;
//sbit key07=P1^1;
//sbit key08=P1^0;
uchar shu;
sbit P3_7=P3^7;
void init()
{
TMOD=0x02;
TH0=0xe6;
TL0=0xe6;
EA=1;
ET0=1;
TR0=1;
flag=0;
qishiok=0;
}
void time0() interrupt 1
{
count++;
if(flag)
{P3_7=~P3_7;}
else
{P3_7=1;}
}
void qishi() //发射起始
{
int a;
count=0;
flag=1;
for(a=0;a<2;a++)
{
endcount=173;
do{}
while(count<endcount);
count=0;
}
flag=0;
count=0;
endcount=173;
do{}
while(count<endcount);
count=0;
qishiok=1;
}
void jieshu() //发射结束
{
int b;
shu=0x02;
count=0;
for(b=0;b<4;b++)
{
flag=1;
do{}while(count<35);
if(shu-(shu/2)*2)
{
ding=45;
}
else
{
ding=15;
}
flag=0;
count=0;
do{}while(ding>count);
count=0;
shu=shu>>1;
}
}
void xinhao(uchar temp) //发射信号
{
int i;
shu=temp;
count=0;
for(i=0;i<8;i++)
{
flag=1;
do{}while(count<35);
if(shu-(shu/2)*2)
{
ding=45;
}
else
{
ding=15;
}
flag=0;
count=0;
do{}while(ding>count);
count=0;
shu=shu>>1;
}
xinhaook=1;
}
void delay()//结束延时
{
int i,j;
// for(i=0;i<400;i++) //原程序
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
}
}
}
void fashe(temp1,temp2,temp3,temp4)
{
init();
qishi();
xinhao(temp1);
xinhao(temp2);
xinhao(temp3);
xinhao(temp4);
jieshu();
delay();
}
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void main()//主程序
{
while(1)
{
P1=0xfe;
if(P1==0xee)
{
fashe(0x00,0xFF,0x45,0xBA);// 1 11101110
}
if(P1==0xde)
{
fashe(0x00,0xFF,0x44,0xBB);// 2 11011110
}
if(P1==0xbe)
{
fashe(0x00,0xFF,0x07,0xF8);// 3 10111110
}
if(P1==0x7e)
{
fashe(0x00,0xFF,0x16,0xE9);// A 01111110
}
P1=0xfd;
if(P1==0xed)
{
fashe(0x00,0xFF,0x0C,0xF3);// 4
}
if(P1==0xdd)
{
fashe(0x00,0xFF,0x08,0xF7);// 5
}
if(P1==0xbd)
{
fashe(0x00,0xFF,0x42,0xBD);// 6
}
if(P1==0x7d)
{
fashe(0x00,0xFF,0x47,0xB8);// B
}
P1=0xfb;
if(P1==0xeb)
{
fashe(0x00,0xFF,0x0C,0xF3);// 7
}
if(P1==0xdb)
{
fashe(0x00,0xFF,0x08,0xF7);// 8
}
if(P1==0xbb)
{
fashe(0x00,0xFF,0x42,0xBD);// 9
}
if(P1==0x7b)
{
fashe(0x00,0xFF,0x47,0xB8);// C
}
P1=0xf7;
if(P1==0xe7)
{
fashe(0x00,0xFF,0x0C,0xF3);// *
}
if(P1==0xd7)
{
fashe(0x00,0xFF,0x08,0xF7);// 0
}
if(P1==0xb7)
{
fashe(0x00,0xFF,0x42,0xBD);// #
}
if(P1==0x77)
{
fashe(0x00,0xFF,0x47,0xB8);// D
}
}
}
|