本帖最后由 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[17] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77,
0x7c, 0x39, 0x5e, 0x79, 0x71, 0x73};
code unsigned char Yube_cho[8] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
unsigned char temp[8];
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[4] = Tube_table[num % 10];
temp[3] = Tube_table[num /10 % 10];
temp[2] = Tube_table[num /100 % 10];
temp[1] = Tube_table[num /1000 % 10];
temp[0] = Tube_table[num /10000 % 10];
}
//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[i + 3];
Led_control = 1;
Led_control = 0;
DataOut = temp[i];
Led_show = 1;
Led_show = 0;
if (i < 4)
{
i ++;
}
else
{
i = 0;
}
}
|