为什么加上三极管显示就不正常,一个一个显示,但去掉三极管就显示正常了
单片机源程序如下:
- #include<reg51.h>
- #define uin unsigned int
- #define uchar unsigned char
- unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
- unsigned char code tablet[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
- unsigned char code show[]={0x70,0xB0,0xD0,0xE0};//三极管换成0x10,0x20,0x40,0x80
- unsigned int count=0;
- unsigned char group[10]={0};
- sbit P3_2=P3^2;
- sbit P3_4=P3^4;
- sbit P3_5=P3^5;
- sbit P3_6=P3^6;
- sbit P3_7=P3^7;
-
- uin math,i,j,k,g,special;
- uchar p=0,o=0,b=0,m=0,t=0,h=0,q=1;
- void delay(unsigned int time)
- {
- unsigned int j=0;
- for(;time>0;time--)
- for(j=0;j<100;j++);
- }
- key1() interrupt 2{
- if(m==0){
- math=count;
- group[p]=math;
- p++;
- o++;
- if(p>=10) m=1;
- }}
- software() interrupt 1{
-
- t++;
- if(t==2)
- {count++;t=0;}
- TH0=0x3c;
- TL0=0xb0;
- }
- void clr()
- { uchar c;
- for(c=0;c<10;c++)
- group[c]=0;}
-
-
- void main(){
-
- TMOD=0x01;
- TH0=0x3c;
- TL0=0xb0; P3_2=1;
- IT0=1;EX0=1;EA=1;
- IT1=1;EX1=1;
- TR0=0; ET0=1;
- while(1)
- { P3_2=1;
-
- if(b==0){
- for(i=0;i<4;i++)
- { if(i==0)
- {P2=show[i];
- P0=table[p];
- }
- else if(i==1)
- {P2=show[i];
- P0=table[count/100];
-
- }
- else if(i==2)
- {P2=show[i];
- P0=tablet[count/10];
-
- }
- else if(i==3)
- {P2=show[i];
- P0=table[count%10];
- }
- delay(20);}}
-
- if(P3_7==0)
- {delay(10);
- if(P3_7==0)
- {TR0=1;b=0;m=0;
- }
-
- if(P3_4==0)
- {delay(10);
- if(P3_4==0)
- {TR0=0;
- }
-
- if(P3_5==0)
- {delay(10);
- if(P3_5==0)
- { p=0;
- b=1;
- TR0=0;
- count=0;
- if(b==1){
- for(k=0;k<o;k++)
- { special=group[p];
- for(g=0;g<20;g++)
- {
- for(i=0;i<4;i++)
- { if(i==0)
- {P2=show[i];
- P0=table[q];
- delay(10);
- }
- else if(i==1)
- {P2=show[i];
- P0=table[special/100];
- delay(10);
- }
- else if(i==2)
- {P2=show[i];
- P0=tablet[special/10%10];
- delay(10);}
- else if(i==3)
- {P2=show[i];
- P0=table[special%10];
- delay(10);}
-
- }}
- p++;
- q++;
- if(p==o)
- {b=0;count=0;p=0;i=0;k=0;special=0;o=0;q=1;clr();P3_2=0;delay(10);}
- }
- }}
- }
- if(P3_6==0)
- {delay(10);
- if(P3_6==0)
- { P3_2=0;
- delay(15);
-
- TR0=0;
- count=0;b=0;p=0;i=0;m=0;special=0;q=1;clr();
-
- }
- }
- }
- }
- }
- }
复制代码
原理图.7z
(33.08 KB, 下载次数: 8)
|