求大神帮忙看看 按键1-8 红外线遥控数码管不显示 不知道为什么...
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
sbit IRIN=P3^2;
uchar x;
uchar y;
uchar z;
uchar irtime;
uchar i;
uchar n;
uchar irreceok;
uchar ircode[4];
uchar temp;
uchar irprosok;
uchar k;
uchar w;
uchar code dulasmg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(z){
for(x=z;x>0;x--)
for(y=110 ;y>0;y--); }
sbit dula=P2^6;
sbit wela=P2^7;
uchar irdata[33];
void irpros(void);
void irwork(void);
void timer0init(void){
ET0=1;
EA=1;
TMOD=0x02;
TH0=0x00;
TL0=0x00;
TR0=1;}
void ex_init(void){
IT0=1;
EX0=1;
EA=1;}
void timer0() interrupt 1 {
irtime++;
}
void ex0_isr(void) interrupt 0{
static bit iflag;
static uchar numbit;
if(iflag){
if(irtime<58&&irtime>=30)
numbit=0;
irdata[numbit]=irtime;
irtime=0;
numbit++;
if(numbit==33)
{numbit=0;
irreceok=1;}
}
else {
irtime=0;
iflag=1;
}
}
void irpros(void){
k=1;
for(n=0;n<4;n++){
for(i=i;i<=8;i++)
{
if(irdata[k]>7)
{temp=temp|0x80;}
if(i<8){
temp=temp>>1;}
k++;
}
ircode[n]=temp;
temp=0; }
irprosok=1;
}
void irwork(void){
switch(ircode[2])
{
case 0x0c:P0=dulasmg[1];break;
case 0x18:P0=dulasmg[2];break;
case 0x5e:P0=dulasmg[3];break;
case 0x08:P0=dulasmg[4];break;
case 0x1c:P0=dulasmg[5];break;
case 0x5a:P0=dulasmg[6];break;
case 0x42:P0=dulasmg[7];break;
case 0x52:P0=dulasmg[8];break;
default:break;
}
irprosok=0;
}
void main(void){
ex_init();
timer0init();
P0=0xfb;
wela=1;
wela=0;
while(1){
if(irreceok)
{
irpros();
irreceok=0;}
if(irprosok)
{
irwork();
}
}
}
#include<intrins.h>
#define uchar unsigned char
sbit IRIN=P3^2;
uchar x;
uchar y;
uchar z;
uchar irtime;
uchar i;
uchar n;
uchar irreceok;
uchar ircode[4];
uchar temp;
uchar irprosok;
uchar k;
uchar w;
uchar code dulasmg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(z){
for(x=z;x>0;x--)
for(y=110 ;y>0;y--); }
sbit dula=P2^6;
sbit wela=P2^7;
uchar irdata[33];
void irpros(void);
void irwork(void);
void timer0init(void){
ET0=1;
EA=1;
TMOD=0x02;
TH0=0x00;
TL0=0x00;
TR0=1;}
void ex_init(void){
IT0=1;
EX0=1;
EA=1;}
void timer0() interrupt 1 {
irtime++;
}
void ex0_isr(void) interrupt 0{
static bit iflag;
static uchar numbit;
if(iflag){
if(irtime<58&&irtime>=30)
numbit=0;
irdata[numbit]=irtime;
irtime=0;
numbit++;
if(numbit==33)
{numbit=0;
irreceok=1;}
}
else {
irtime=0;
iflag=1;
}
}
void irpros(void){
k=1;
for(n=0;n<4;n++){
for(i=i;i<=8;i++)
{
if(irdata[k]>7)
{temp=temp|0x80;}
if(i<8){
temp=temp>>1;}
k++;
}
ircode[n]=temp;
temp=0; }
irprosok=1;
}
void irwork(void){
switch(ircode[2])
{
case 0x0c:P0=dulasmg[1];break;
case 0x18:P0=dulasmg[2];break;
case 0x5e:P0=dulasmg[3];break;
case 0x08:P0=dulasmg[4];break;
case 0x1c:P0=dulasmg[5];break;
case 0x5a:P0=dulasmg[6];break;
case 0x42:P0=dulasmg[7];break;
case 0x52:P0=dulasmg[8];break;
default:break;
}
irprosok=0;
}
void main(void){
ex_init();
timer0init();
P0=0xfb;
wela=1;
wela=0;
while(1){
if(irreceok)
{
irpros();
irreceok=0;}
if(irprosok)
{
irwork();
}
}
}