51单片机普中开发版 这个是按键p3_0控制数码管左边显示20-50右边00-50同时显示,怎么样再加一个按键p3_1控制左边的数码管显示20-50让他们分开显示
单片机源程序如下:
#include <REGX52.H>
#include "Delay.h"
unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F, 0x00};
void Nixie(unsigned char Location,Number)
{
switch(Location)
{
case 1:P2_4=1;P2_3=1;P2_2=1;break;
case 2:P2_4=1;P2_3=1;P2_2=0;break;
case 3:P2_4=1;P2_3=0;P2_2=1;break;
case 4:P2_4=1;P2_3=0;P2_2=0;break;
case 5:P2_4=0;P2_3=1;P2_2=1;break;
case 6:P2_4=0;P2_3=1;P2_2=0;break;
case 7:P2_4=0;P2_3=0;P2_2=1;break;
case 8:P2_4=0;P2_3=0;P2_2=0;break;
}
P0=NixieTable[Number];
}
void Timer0Init(void) //1毫秒@11.0592MHz
{
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x66; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
PT0=0;
}
unsigned char num=0,ber=20;
void main()
{
while(1){ if(P3_0==0)break; }
Timer0Init();
while(1)
{
Nixie(5, num/1000);
Delay(1);
Nixie(5, 10);
Nixie(6, num/100);
Delay(1);
Nixie(6, 10);
Nixie(7, num/10);
Delay(1);
Nixie(7, 10);
Nixie(8, num%10);
Delay(1);
Nixie(8, 10);
break;
Nixie(1,ber/1000);
Delay(1);
Nixie(1, 10);
Nixie(2, ber/100);
Delay(1);
Nixie(2, 10);
Nixie(3, ber/10);
Delay(1);
Nixie(3, 10);
Nixie(4, ber%10);
Delay(1);
Nixie(4, 10);
}
}
unsigned char KeyNum;
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count ;
TL0 = 0x66; //设置定时初值
TH0 = 0xFC; //设置定时初值
T0Count++;
if(T0Count>=100)
{ T0Count=0;
if(num<50)
{ num ++; }
else
{ num=0; }
if(ber<50)
{ ber ++; }
else
{ ber=20; }
}
} |