|
上面是软件仿真的结构图。实现目标是按键1按下显示1,按两下显示21,按三下显示321,一直下去直到八下显示87654321;
每按一下K2键则少以为 ,如果显示为54321,按下K2后则显示4321;按下K3键则清零。
我的程序如下不知道行不行,请高手们帮忙看一看 。。谢谢!!
有不对的帮忙改一下 。。我的qq 609873137,如果需要仿真图形的话我可以发给你,以便你们能进行仿真。
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
uint count;
uchar code show[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code disp[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar data disdata[8];
void delayms(uint i)
{
uint a,b;
for(a=0;a
for(b=0;b<120;b++);
}
void diplay()
{
uchar i;
extern uint count;
disdata[0]=0x06;
disdata[0]=0x5b;
disdata[0]=0x4f;
disdata[0]=0x66;
disdata[0]=0x6d;
disdata[0]=0x7d;
disdata[0]=0x07;
disdata[0]=0x7f;
for(i=0;i
{
P0=show[disdata];
P2=disp;
delayms(2);
}
}
void keyscan()
{
extern uint count;
if(K1==0)
{
delayms(10);
if(K1==0)
{
while (K1==0)
{
count++;
if(count>=8)
count=8;
}
}
else
count=count;
}
if(K2==0)
{
delayms(10);
if(K2==0)
{
while(K2==0)
{
count=count-1;
if(count<=0)
count=0;
}
}
else
count=count;
}
if(K3==0)
{
delayms(10);
if(K3==0)
{
while(K3==0)
{
count=0;
disdata[0]=0x3f;
P3=disp[0];
}
}
else
count=count;
}
}
void main ()
{
extern uint count;
count=0;
while (1)
{
display();
keyscan();
}
}
|
|