📄 定时煮饭.c
字号:
#include"reg52.h"
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit P3_3=P3^3 ;
sbit CALL=P3^1 ;
sbit P3_2=P3^2 ;
sbit P1_0=P1^0 ;
uint table1[]={1,2,3,25,4,5,6,25 ,7,8,9,25 ,25 ,0,25 ,25,};
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6F};
code char key_code[]={0x77,0xb7,0xd7,0xe7,
0x7b,0xbb,0xdb,0xeb,
0x7d,0xbd,0xdd,0xed,
0x7e,0xbe,0xde,0xee};
code ksp[4]={0x7f,0xbf,0xdf,0xef};
uint one,two,m;
main()
{//uint one,two,m;
uint ch;
uchar a,b;
char gotkey();
void display(uint ,uint );
char keypad_scan();
void delay();
while(gotkey()!=3);
while((b=gotkey())==3);
ch=b;
one=table1[ch];
while(gotkey()!=7);
while((a=gotkey())==7);
ch=a;
two=table1[ch];
m=one*10+two ;
TMOD=0x11;
TH0=0x4c;
TL0=0x00;
EA=1;
TR0=1;
ET0=1;
while(1)
{
display(two,one);
}
while(1);
}
void int0() interrupt 1 using 1
{
uint count0;
count0++;
if(count0==30)
{count0=0;
m--;
if(m)
{one=m/10;
two=m%10;
}
else
{CALL =0; //饭熟报警
one=0;two=0;
ET0=0;
}
}
P1_0=!P1_0;
TH0=0x4c;
TL0=0x00;
}
void display(uint two,uint one)
{P3_3=0;P3_2=1;
P0=table[two];
delay();
P0=0x00;
P3_3=1;P3_2=0;
P0=table[one];
delay();
P0=0x00;
}
void delay (void)
{ /* 时间延迟函数 */
unsigned char i,j;
for (i=0;i<5;i++)
for(j=0;j<255;j++);
}
char keypad_scan()
{
char key,i;
P2=0xf0;
while (P2!=0xf0);
do{
for(i=0;i<=3;i++)
{
P2=ksp[i];
if(P2!=ksp[i])
{
delay();
key=P2;
if(key!=ksp[i])
{
return(key);
}
}
}
} while(1);
}
// 检查是否有按键按下
char gotkey()
{
char temp,i;
temp=keypad_scan();
for (i=0;i<=15;i++) {
if(temp==key_code[i]) return(i);
}
return(16);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -