前几天有个同学让我帮他做作业,写了一段程序,不知道写得怎么样?作业图片如下,程序如下,仿真图如下。欢迎同行点评点评。。。。
#include
void delay_500ms()
{
unsigned char i,j;
for(i=1000;i--;i>0)
for(j=500;j--;j>0);
}
unsigned char const number1[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
unsigned char const number2[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
int flag=0,n=0,m=0,flagb=0;
sbit key_c=P3^4;
sbit key_d=P3^5;
void main()
{
P1=0X00;
P2=0X00;
P3=0XFF;
TCON=0X05;
IE=0X85;
while(1)
{
if(flag==0)
{
if(flagb==0)
{
P1=number1[n++];
delay_500ms();
if(n==10)
{
n=0;
P2=number2[++m];
if(m==10)m=0;
}
}
else
{
P1=number1[n];
P2=number2[m];
}
}
else
{
if((key_c==0)&(n<10))
{
while(~key_c);
n++;
if((n==10)&(m<10))
{n=0;m++;}
}
if((key_d==0)&(n>=0))
{
while(~key_d);
n--;
if((n<0)&(m>0))
{n=9;m--;}
}
P1=number1[n];
P2=number2[m];
}
}
}
void KEY_A(void) interrupt 0
{
IE0=0;
flag=~flag;
}
void KEY_B(void) interrupt 2
{
IE1=0;
flagb=~flagb;
n=0;
m=0;
}
|