📄 cs12-3.c
字号:
#include <REG51.H>
#include <MATH.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar ACT[4]={0xfe,0xfd,0xfb,0xf7};
/*********************************************************/
sbit P3_2=P3^2;
sbit P3_3=P3^3;
sbit P3_5=P3^5;
int c,f;
int temp;
uchar status;
/*******************************************************/
void key_s1(void);
void key_s2(void);
void key_s4(void);
int conv(int fin);
void delay_1ms(void);
/********************************************************/
void main(void)
{int temp_f,temp_c;
while(1)
{
key_s1();
key_s2();
key_s4();
if(status==0)
{
if(f<0)
{temp_f=abs(f);
P0=SEG7[temp_f%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(temp_f%100)/10];P2=ACT[1];
delay_1ms();
P0=SEG7[(temp_f/100)%10];P2=ACT[2];
delay_1ms();
P0=0x40;P2=ACT[3];
delay_1ms();
}
else
{
P0=SEG7[f%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(f%100)/10];P2=ACT[1];
delay_1ms();
P0=SEG7[(f/100)%10];P2=ACT[2];
delay_1ms();
}
}
else
{
c=conv(f);
if(c<0)
{temp_c=abs(c);
P0=SEG7[temp_c%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(temp_c%100)/10];P2=ACT[1];
delay_1ms();
P0=SEG7[(temp_c/100)%10];P2=ACT[2];
delay_1ms();
P0=0x40;P2=ACT[3];
delay_1ms();
}
else
{
P0=SEG7[c%10];P2=ACT[0];
delay_1ms();
P0=SEG7[(c%100)/10];P2=ACT[1];
delay_1ms();
P0=SEG7[(c/100)%10];P2=ACT[2];
delay_1ms();
}
}
}
}
/***********************************************************/
void key_s1(void)
{
if(!P3_2)
{if(temp>50)temp=0;
if(temp==0)f++;
if(f>999)f=999;
temp++;
}
}
/*******************************************************/
void key_s2(void)
{
if(!P3_3)
{if(temp>50)temp=0;
if(temp==0)f--;
if(f<-500)f=-500;
temp++;
}
}
/************************************************************/
void key_s4(void)
{
if(!P3_5)status=1;
else status=0;
}
/****************************************************************/
int conv(int fin)
{int ddata;
ddata=fin-32;
ddata=(ddata*5)/9;
return ddata;
}
/*************************************************************/
void delay_1ms(void)
{
uint k;
for(k=0;k<121;k++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -