📄 1602显示带键盘.txt
字号:
#include <at89x51.h>
#include <key.h>
#include <lcd1602.h>
bit flag;
float q;
int dingshi=0x01;
int x,y,z;
bit b=0;
float i,j,m,k;
float H,KK,N;
void dingshiin(void);
main()
{
BEGAIN:
P1 = 0xff;
LCD_Initial();
P2=0XF0;
GotoXY(0,0);
Print("Input E : ");
GotoXY(0,1);
Print(" ");
m=0;
k=0;
i=0;
q=0;
while(1)
{
while(1)
{
m=keynum();
if(m>=0&&m<=9||m==15||m==14||m==12)
{
z=m;
Delay1ms(150);
break;
}
}
if(m>=0&&m<=9)
{
i++;
}
if(z==12)
{
goto BEGAIN;
}
if(z==15)
{
q=k;
GotoXY(0,1);
Print(" ");
GotoXY(0,1);
Print("OK!!");
Delay1ms(1000);
break;
}
if(i==1)
{k=z;}
if(i==2)
{
k=k*10+z;
}
if(i==3)
{
k=k*10+z;
}
if(i>7)
{
GotoXY(0,1);
Print(" ERROR!! ");
Delay1ms(500);
goto BEGAIN;
}
IntToStr(k,&TempBuffer[0],0);
GotoXY(0,1);
Print(&TempBuffer[0]);
P2=0XF0;
Delay1ms(150);
}
LCD_Initial();
Delay1ms(150);
Print("Waiting.........");
Delay1ms(1000);
if(z==14)
{
goto BEGAIN;
}
GotoXY(0,0);
Delay1ms(500);
GotoXY(0,0);
Print("Used E: ");
y=0;
IntToStr(y,&TempBuffer[0],0);
GotoXY(12,0);
Print(&TempBuffer[0]);
GotoXY(0,1);
Print("Remain E: ");
IntToStr(k,&TempBuffer[0],0);
GotoXY(11,1);
Print(&TempBuffer[0]);
P1_1 = 0;
dingshiin();
while(1)
{
if(k <= 10)
{
P1_0 = 0;
}
else
P1_0 = 1;
}
}
void dingshiin(void)
{
ET1=0;
TMOD=0x15; //定时器0为计数器方式,定时器1定时方式1
TH0=0X00;
TL0=0X00;
TR0=1;//启动定时器0
TH1=0x4c;//定时器1初值设定
TL1=0x00;
ET1=1;
TR1=1;
EA=1;
}
void timer_ISP(void) interrupt 3
{
dingshi++;
TH1=0x4c;
TL1=0X03;
b=0;
if(dingshi==80)
{
dingshi=0;
y++;
k--;
if(k <= 0)
{
P1_1 = 1;
TH0=0x00;
TL0=0x00;
TR0=1;
ET1=0;
EA=0;
}
GotoXY(0,0);
Print("Used E: ");
IntToStr(y,&TempBuffer[0],0);
GotoXY(12,0);
Print(&TempBuffer[0]);
GotoXY(0,1);
Print("Remain E: ");
IntToStr(k,&TempBuffer[0],0);
GotoXY(11,1);
Print(&TempBuffer[0]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -