软件使用:keil,proteus
程序:
#include <reg51.h>
#define u8 unsigned char
#define u16 unsigned int
#define SMG_XS P2
#define SMG_XM P0
unsigned char code smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳极
%使用的数码管为共阳的
unsigned int shuzi;
sbit s1=P1^0;
sbit s2=P1^3;
void delay(u16 i)
{
while(i--);
}
void main()
{
shuzi=99;
while(1)
{
SMG_XS=smg[shuzi%10]; //取余
SMG_XM=smg[shuzi/10];
if(s1==0){ //加
delay(500);
if(s1==0){
shuzi++;
if(shuzi>99){
shuzi=0;
}
}
while(!s1);
}
if(s2==0){ //减
delay(500);
if(s2==0){
shuzi--;
}
while(!s2);
}
}
}
proteus作图: