📄 cs13-2.c
字号:
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[5]={0xfe,0xfd,0xfb,0xf7,0xef};
uint data shuzu[10];
/*******************************************************************/
uchar status;
uchar temp;
int max,f;
/*************************************************************************/
void delay_1ms(void)
{
uint k;
for(k=0;k<121;k++);
}
/************************************************************************/
void dis_max(void)
{ P0=SEG7[max%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(max/10)%10];P2=ACT[1];
delay_1ms();
P0=SEG7[max/100];P2=ACT[2];
delay_1ms();
}
/***************************************************************************/
void dis_input(void)
{ P0=SEG7[f%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(f/10)%10];P2=ACT[1];
delay_1ms();
P0=SEG7[f/100];P2=ACT[2];
delay_1ms();
P0=SEG7[status];P2=ACT[4];
delay_1ms();
}
/***************************************************************************/
void key_s1(void)
{
P3=0xff;
if(P3==0xfb)
{if(temp>30)temp=0;
if(temp==0)f++;
if(f>999)f=999;
temp++;
delay_1ms();
}
}
/**************************************************************/
void key_s2(void)
{
P3=0xff;
if(P3==0xf7)
{if(temp>30)temp=0;
if(temp==0)f--;
if(f<0)f=0;
temp++;
delay_1ms();
}
}
/********************************************************************/
void key_s3(void)
{
P3=0xff;
if(P3==0xef)
{
switch (status)
{ case 0:shuzu[0]=f;break;
case 1:shuzu[1]=f;break;
case 2:shuzu[2]=f;break;
case 3:shuzu[3]=f;break;
case 4:shuzu[4]=f;break;
case 5:shuzu[5]=f;break;
case 6:shuzu[6]=f;break;
case 7:shuzu[7]=f;break;
case 8:shuzu[8]=f;break;
case 9:shuzu[9]=f;break;
default:break;
}
}
}
/**********************************************************************/
void key_s4(void)
{
P3=0xff;
if(P3==0xdf)
{if(temp>100)temp=0;
if(temp==0)status++;
if(status>10)status=0;
temp++;
delay_1ms();
}
}
/*************************************************************/
void conv(void)
{
uchar i;
max=shuzu[0];
for(i=1;i<10;i++)
{
if(shuzu[i]>max)max=shuzu[i];
}
}
/**********************************************************/
void main(void)
{
while(1)
{
key_s1();
key_s2();
key_s3();
key_s4();
conv();
if(status==10)dis_max();
else dis_input();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -