单片机89c51,帮我编个C程序,顺便说一下用KeiluVision3仿真调试软件的调试步骤

2024-12-14 01:43:38
推荐回答(1个)
回答1:

#include

sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;

sbit p25=P2^5;
sbit p26=P2^6;

typedef unsigned char uint8;

code uint8 num[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,};
uint8 count,shi,ge,i;
delay()
{
uint8 i=1000;
while(i--);
}

display()
{
shi=count/10;
ge=count%10;

p25=0;
P0=num[shi];
p25=1;
p26=0;
P0=num[ge];
p26=1;

}
main()
{
while(1)
{
if(p20==0)
{
delay();
if(p20==0)
{
count++;
}
}
if(p21==0)
{
delay();
if(p21==0)
{
count--;
}
}
if(p22==0)
{
delay();
if(p22==0)
{
count=0;
}
}

display();
}

}