单片机四位七段数码管按键加减个十百千位的数值
用三个按键改变个位,十位,百位,千位,一个加键,一个减键,还有一个换位。具体的代码是怎么样的,求大佬回答 本帖最后由 kylin121380 于 2020-11-18 12:44 编辑换位是?加减可参考下面,用的是独立式按键,短按加减,长按快速加减
#include<reg52.h>
#define DataOut P1
#define DataIn P0
sbit Led_show = P2^1;
sbit Led_control = P2^0;
sbit add = P0^0;
sbit dec = P0^1;
code unsigned char Tube_table = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77,
0x7c, 0x39, 0x5e, 0x79, 0x71, 0x73};
code unsigned char Yube_cho = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
unsigned char temp;
unsigned char TH0H, TH0L;
unsigned int time_count;//9999计数
void ConfigTime0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200 / 12;
tmp = (tmp * ms) / 1000;
tmp = 65536- tmp ;
tmp = tmp + 18;
TH0H = (unsigned char)(tmp >> 8);
TH0L = (unsigned char) tmp;
TMOD &= 0XF0;
TMOD |= 0x01;
TH0 = TH0H;
TL0 = TH0L;
TR0 = 1;
ET0 = 1;
}
void Delay(unsigned int i)
{
unsigned int j;
for (;i > 0; i --)
{
for(j = 20; j > 0; j --);
}
}
void temp_calc(unsigned int num)
{
temp = Tube_table;
temp = Tube_table;
temp = Tube_table;
temp = Tube_table;
temp = Tube_table;
}
//9999计时,长短按加减时间
void main()
{
unsigned long i, count;
unsigned char j, flag = 0;
//unsigned int num;
ConfigTime0(1);
EA = 1;
while(1)
{
temp_calc(time_count);
j = DataIn;
Delay(15);
if ((j == DataIn) & (0x7f == DataIn))
{
while((j == DataIn) & (0x7f == DataIn))
{
i ++;
if (i > 1000)
{
i --;
count ++;
if ((count == 50) & (time_count < 65536))
{
flag = 1;
count = 0;
time_count += 10;
}
}
temp_calc(time_count);
}
i = 0;
if(flag)
{
flag = 0;
}
else
{
time_count += 100;
}
temp_calc(time_count);
}
if ((j == DataIn) & (0xbf == DataIn))
{
while((j == DataIn) & (0xbf == DataIn))
{
i ++;
if (i > 1000)
{
i --;
count ++;
if ((count == 50) & (time_count > 0))
{
flag = 1;
count = 0;
time_count -= 10;
}
}
temp_calc(time_count);
}
i = 0;
if(flag)
{
flag = 0;
}
else
{
time_count -= 100;
}
temp_calc(time_count);
}
}
}
void time0_interrupt() interrupt 1
{
static unsigned int i, count ;
TH0 = TH0H;
TL0 = TH0L;
count ++;
if (count == 1000)
{
count = 0;
time_count ++;
}
DataOut = 0;
Led_show = 1;
Led_show = 0;
DataOut = Yube_cho;
Led_control = 1;
Led_control = 0;
DataOut = temp;
Led_show = 1;
Led_show = 0;
if (i < 4)
{
i ++;
}
else
{
i = 0;
}
}
页:
[1]