2020-12-06

数码管显示递增(0~100)
#include <REGX52.H>

int x=0,y=0,n=0,m=0;
void Delay1ms(int shijian)
{
while(shijian)
{
unsigned char i, j;

i = 2;
j = 239;
do
{
	while (--j);
} while (--i);
shijian--;
}

}

sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;

unsigned char nix[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00,0x80} ;
void nixie(unsigned char a,b,c,d,w,x,y,z)
{
switch(a)
{
case 1:
P24=1,P23=1,P22=1;
break;
case 2:
P24=1,P23=1,P22=0;
break;
case 3:
P24=1,P23=0,P22=1;
break;
case 4:
P24=1,P23=0,P22=0;
break;
case 5:
P24=0,P23=1,P22=1;
break;
case 6:
P24=0,P23=1,P22=0;
break;
case 7:
P24=0,P23=0,P22=1;
break;
case 8:
P24=0,P23=0,P22=0;
break;
}
P0=nix[w];
Delay1ms(1);
P0=0x00;
switch(b)
{
case 1:
P24=1,P23=1,P22=1;
break;
case 2:
P24=1,P23=1,P22=0;
break;
case 3:
P24=1,P23=0,P22=1;
break;
case 4:
P24=1,P23=0,P22=0;
break;
case 5:
P24=0,P23=1,P22=1;
break;
case 6:
P24=0,P23=1,P22=0;
break;
case 7:
P24=0,P23=0,P22=1;
break;
case 8:
P24=0,P23=0,P22=0;
break;
}
P0=nix[x];
Delay1ms(1);
P0=0x00;
switch©
{
case 1:
P24=1,P23=1,P22=1;
break;
case 2:
P24=1,P23=1,P22=0;
break;
case 3:
P24=1,P23=0,P22=1;
break;
case 4:
P24=1,P23=0,P22=0;
break;
case 5:
P24=0,P23=1,P22=1;
break;
case 6:
P24=0,P23=1,P22=0;
break;
case 7:
P24=0,P23=0,P22=1;
break;
case 8:
P24=0,P23=0,P22=0;
break;
}
P0=nix[y];
Delay1ms(1);
P0=0x00;
switch(d)
{
case 1:
P24=1,P23=1,P22=1;
break;
case 2:
P24=1,P23=1,P22=0;
break;
case 3:
P24=1,P23=0,P22=1;
break;
case 4:
P24=1,P23=0,P22=0;
break;
case 5:
P24=0,P23=1,P22=1;
break;
case 6:
P24=0,P23=1,P22=0;
break;
case 7:
P24=0,P23=0,P22=1;
break;
case 8:
P24=0,P23=0,P22=0;
break;
}
P0=nix[z];
Delay1ms(1);
P0=0x00;
}
void Timer0Init(void)
{

TMOD &= 0xF0;	
TMOD |= 0x01;		
TL0 = 0x18;	
TH0 = 0xFC;	
TF0 = 0;	
TR0 = 1;		
		ET0=1;
	EA=1;

}
void timer0_routine() interrupt 1
{
static unsigned int t0count;
TL0 = 0x18;
TH0 = 0xFC;
t0count++;
if(t0count>=500)
m++;
if(m10)
{
m=0;
n=n++;
if(n
10)
{
n=0;
y++;
if(y10)
{
y=0;
x++;
if(x
10)
{
x=0;
}
}
}
}
nixie(4,3,2,1,m,n,y,x);

	t0count=0;

}
void main()
{
Timer0Init();
while(1)
{;}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值