|
要求和仿真出现的问题如图 不知道是代码/电路问题还是仿真自身的不足
Proteus没有带dp的单管 就用了mpx4
代码如下
- #include<reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- uchar code segtab[]=
- {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,
- 0x83,0xc6,0xa1,0x86,0x8e,0x89,0x8c,0xff,0xbf,0x8d};
- uchar dbuf[6]={0,0,0,0,0x12,0x11};
- sbit SPK=P1^0;
- sbit K1=P2^4;
- sbit K2=P2^5;
- sbit K3=P2^6;
- sbit K4=P2^7;
- bit start;
- void delay(void)
- { uchar i;
- for(i=0;i<200;i++);
- }
- void int0(void)interrupt 0
- { start=1;
- }
- void disp(void)
- { uchar n,bsel;
- bsel=0x01;
- for(n=0;n<6;n++)
- { P2=bsel;
- P0=segtab[dbuf[n]];
- bsel=_crol_(bsel,1);
- delay();
- P0=0xff;
- }
- }
- void main(void)
- {
- uchar i;
- start=0;
- EX0=1;
- IT0=1;
- EA=1;
- while(1)
- { while(start==0)disp();
- start=0;
- dbuf[5]=0;
- while((P2&0x0f)==0x0f)disp();
- for(i=0;i<10;i++)disp();
- if((P2&0x0f)!=0x0f)
- {
- if(K1==0)i=1;
- else if(K2==0)i=2;
- else if(K3==0)i=3;
- else if(K4==0)i=4;
- dbuf[5]=i;
- dbuf[i-1]=dbuf[i-1]+1;
- for(i=0;i<200;i++)
- { delay();
- SPK=~SPK;
- }
- }
- }
- }
复制代码
|
-
1.jpg
(2.29 MB, 下载次数: 26)
-
1.gif
(288.34 KB, 下载次数: 33)
|