各位大神 ,请问小弟看这个程序,怎么显示不了16路
时间:10-02
整理:3721RD
点击:
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit P2_4=P2^4;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P3_7=P3^7;
uchar led[]={0XA0,0XBB, 0X62,0X2A, 0X39, 0X2C, 0X24, 0XBA, 0X20,0X28,};//数码管表
uchar duan[]={0xf1,0xf2,0xf4,0xf8};
uchar h;
uchar flag1,flag2,flag3;
uint count,sec=30;
void jianpan();
void buzzer(uint i,uint j);
void delay(int j)
{
int i;
for(i=j;i>0;i--);
}
void display(uchar d,uchar w)
{
int j;
for(j=0;j<4;j++)
{
P2=duan[d];
P0=led[w/10];
jianpan();
P2=duan[d+1];
P0=led[w%10];
jianpan();
}
}
void jianpan()
{
uchar i,n,m,b=0x01;
for(i=0;i<4;i++)
{
P1=~b;
delay(20);
n=P1;
if(n!=b)
if(flag3==1)
{
switch(n) {
case 0xee:flag1=1;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xde:flag1=2;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbe:flag1=3;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7e:flag1=4;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xed:flag1=5;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xdd:flag1=6;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbd:flag1=7;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7d:flag1=8;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xeb:flag1=9;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xdb:flag1=10;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbb:flag1=11;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7b:flag1=12;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);P3_7=1;break;
case 0xe7:flag1=13;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0xd7:flag1=14;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0xb7:flag1=15;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0x77:flag1=16;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
}
}
m=P2&0xf0;
if(m!=0xf0)
switch(m)
{
case 0xe0:flag3=1;TR0=1;P3_4=0;break;
case 0xd0:flag1=0;flag2=0;flag3=0;sec=30;count=0;TR0=0;P3_5=1;P3_4=1;P3_7=1;break;
case 0xb0:if(flag3==0)sec++;break;
case 0x70:if(flag3==0)sec--;break;
}
while(m!=0xf0)m=P2&0xf0;
b<<=1;
}
}
void time0()interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
++count;
if(sec<=5&&count==10)
{
P3_4=~P3_4;
P3_7=0;
}
if(count==20)
{
if(sec<=5&&count==20)
{
P3_4=~P3_4;
P3_7=1;
}
count=0;
sec--;
if(sec==0)
{
flag3=0;
TR0=0;
P3_7=1;
}
}
}
void buzzer(uint i,uint j)
{
while(i--)
{
P3_7=~P3_7;
while(j--)
{
delay(200);
}
P3_7=~P3_7;
}
}
void main()
{
P3_7=1;
TMOD=0x11;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TH1=(65535-65535)/256;
TL1=(65535-65535)%256;
EA=1;
EX0=1;
EX1=1;
IT0=1;
ET0=1;
ET1=1;
while(1)
{
display(flag2,flag1);
display(2,sec);
}
}
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit P2_4=P2^4;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P3_7=P3^7;
uchar led[]={0XA0,0XBB, 0X62,0X2A, 0X39, 0X2C, 0X24, 0XBA, 0X20,0X28,};//数码管表
uchar duan[]={0xf1,0xf2,0xf4,0xf8};
uchar h;
uchar flag1,flag2,flag3;
uint count,sec=30;
void jianpan();
void buzzer(uint i,uint j);
void delay(int j)
{
int i;
for(i=j;i>0;i--);
}
void display(uchar d,uchar w)
{
int j;
for(j=0;j<4;j++)
{
P2=duan[d];
P0=led[w/10];
jianpan();
P2=duan[d+1];
P0=led[w%10];
jianpan();
}
}
void jianpan()
{
uchar i,n,m,b=0x01;
for(i=0;i<4;i++)
{
P1=~b;
delay(20);
n=P1;
if(n!=b)
if(flag3==1)
{
switch(n) {
case 0xee:flag1=1;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xde:flag1=2;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbe:flag1=3;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7e:flag1=4;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xed:flag1=5;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xdd:flag1=6;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbd:flag1=7;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7d:flag1=8;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xeb:flag1=9;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xdb:flag1=10;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0xbb:flag1=11;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);break;
case 0x7b:flag1=12;flag3=0;sec=60;P3_5=0;P3_4=1;buzzer(1,100);P3_7=1;break;
case 0xe7:flag1=13;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0xd7:flag1=14;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0xb7:flag1=15;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
case 0x77:flag1=16;flag3=0;sec=60;P3_5=0;buzzer(1,5);break;
}
}
m=P2&0xf0;
if(m!=0xf0)
switch(m)
{
case 0xe0:flag3=1;TR0=1;P3_4=0;break;
case 0xd0:flag1=0;flag2=0;flag3=0;sec=30;count=0;TR0=0;P3_5=1;P3_4=1;P3_7=1;break;
case 0xb0:if(flag3==0)sec++;break;
case 0x70:if(flag3==0)sec--;break;
}
while(m!=0xf0)m=P2&0xf0;
b<<=1;
}
}
void time0()interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
++count;
if(sec<=5&&count==10)
{
P3_4=~P3_4;
P3_7=0;
}
if(count==20)
{
if(sec<=5&&count==20)
{
P3_4=~P3_4;
P3_7=1;
}
count=0;
sec--;
if(sec==0)
{
flag3=0;
TR0=0;
P3_7=1;
}
}
}
void buzzer(uint i,uint j)
{
while(i--)
{
P3_7=~P3_7;
while(j--)
{
delay(200);
}
P3_7=~P3_7;
}
}
void main()
{
P3_7=1;
TMOD=0x11;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TH1=(65535-65535)/256;
TL1=(65535-65535)%256;
EA=1;
EX0=1;
EX1=1;
IT0=1;
ET0=1;
ET1=1;
while(1)
{
display(flag2,flag1);
display(2,sec);
}
}