📄 jianwen.txt
字号:
#include <reg52.h>
#define Led_0 0xe0
#define Led_1 0xd0
#define Led_2 0xb0
#define Led_3 0x70
sbit JiaWei = P3^4; // 1 加温 0 stop
sbit JianWei = P3^5; // 1 减温 0 stop
//unsigned char setW = 34;
unsigned char xdata *addr;
unsigned char t, Hw, Lw, tt;
unsigned char H_Bit;
unsigned char L_Bit;
unsigned char Temperature;
unsigned char ii=0;
unsigned char value;
unsigned char Key[5][5]={{15,3,2,-1,1},{15,6,5,-1,4},{15,9,8,-1,7},{-1,-1,-1,-1,-1},{15,15,0,-1,15}};
void Keydelay();
unsigned char Keyboard_Scanf();
void Led_Display(unsigned char i,unsigned char number);
void Control(unsigned char i);
unsigned char Key_Scanf();
void delay(int);
void main()
{
//init keyboard
value=0;
H_Bit=0;
L_Bit=0;
P1=0xf0;
PX1=1;
IT1=1;
EX1=1;
IE1=0;
/*
init AD
*/
IT0 = 1; //负跳触发
EX0 = 1; //中断0开
EA = 1; //中断总开
addr = 0x7ffB;
while(1)
{
*addr = t;
Keydelay();//10ms
}
}
void int0read() interrupt 0 using 2
{
EA = 0;
/* 读取传感器当前温度 */
t = *addr;
/* 温度等于(t-140)*2; */
t -= 140;
t *= 2;
/* 16转10进制 */
Hw = t/10;
Lw = t - Hw*10;
/* 温度控制 */
if(Temperature > t){
JiaWei = 1; JianWei = 0;
}else if(Temperature < t){
JiaWei = 0; JianWei = 1;
}else{
JiaWei = 0; JianWei = 0;
}
EA = 1;
}
void delay(int i)
{
while(i--)
{
Led_Display(1,Lw);
Led_Display(0,Hw);
Led_Display(3,H_Bit);
Led_Display(2,L_Bit);
}
}
void Led_Display(unsigned char i,unsigned char number)
{ if(i>=0&&i<5)
if(number>=0&&number<=9)
{
switch(i)
{
case 0: P0=Led_0 | number; break;
case 1: P0=Led_1 | number; break;
case 2: P0=Led_2 | number; break;
case 3: P0=Led_3 | number; break;
default:break;
}
}
}
void Interrupt_Ex0(void) interrupt 2
{
IE1=0;
value= Keyboard_Scanf();
P1=0xf0;
EA=1;
IE1=0;
}
unsigned char Keyboard_Scanf()
{
unsigned char sccode,recode,cow,row,keyword,i=1;
if((P1&0xf0)!=0xf0) //如果列有 0 则进入
{
Keydelay();
if((P1&0xf0)!=0xf0)
{
sccode=0xfe; //置11111110 ;取列号
while( (sccode&0x10) != 0 ) //判断是否循环了3次
{
P1=sccode; //P1置11111110
if((P1&0xf0)!=0xf0) ////P1与11111000相与看是否还是11111000
{
recode=(P1&0xf0)|0x0f; //P1与11111000相与并与00000111相或,取出行号
cow=(~sccode)>>1; //列号右移一位,
row=(~recode)>>5; //行号右移四位
keyword=Key[cow][row]; //返回键值
Control(keyword);
return keyword;
}
else
sccode=(sccode<<1)|0x01; //P1与11111000相与还是11111000,,右移一位,P1低三位依次取101、011
}
}
}
return keyword; ///没键按下,则返回原来的值
}
void Keydelay()
{
int iii = 100;
while(iii--){
Led_Display(1,Lw);
Led_Display(0,Hw);
Led_Display(2,H_Bit);
Led_Display(3,L_Bit);
}
}
void Interrupt_Ex1(void) interrupt 2
{
IE1=0;
value= Keyboard_Scanf();
P1=0xf0;
EA=1;
IE1=0;
}
void Control(unsigned char i)
{
if(i>=0&&i<=9)
{
ii=~ii;
if(ii==0)
L_Bit=i;
if(ii==0xff)
H_Bit=i;
}
if(i==15)
{
Temperature=H_Bit*10+L_Bit;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -