?? a.c
字號:
#include <reg51.h>
#include <stdio.h>
#include <string.h>
#include <intrins.h>
#include <absacc.h>
#include "1602.h"
#include "18B20.h"
#define uchar unsigned char
#define uint unsigned int
sbit buzzer=P2^0;
sbit relay=P3^6;
sbit sub=P2^1;
sbit add=P2^2;
sbit esc=P2^3;
sbit ok=P2^4;
/*****************全局變量的定義******************/
uchar data time[]="Time:21:24:30";
//uchar data tmpr[]="Tmpr: . C";
uchar data j=0; //計算循環次數
//uint data t=0; //讀出的溫度數據
uchar dp=0x80; //記錄光標位置
//uchar neg=0; //零下溫度標志
//阻塞函數
void Wait(uchar i) //i=0時等待松開,i為1時等待按下
{
TR0=0;
if(i==0)
{
while((sub==0)||(add==0)||(esc==0)||(ok==0)) //等待按鍵松開
{
TR0=1;
Delay5Ms();
TR0=0;
}
}
else
{
while((sub==1)||(add==1)||(esc==1)||(ok==1)) //等待按鍵按下
{
TR0=1;
Delay5Ms();
TR0=0;
}
}
}
Timer() interrupt 1 //定時器0溢出
{
uint i;
TH0=0x4c;
TL0=0x5a;
j++;
if(j==20) //T1每50ms溢出1次,20次后為1秒
{
time[12]++;
if(time[12]==':')
{
time[12]='0';
time[11]++;
if(time[11]=='6')
{
time[11]='0';
time[9]++;
if(time[9]==':')
{
time[9]='0';
time[8]++;
if(time[8]=='6')
{
time[8]='0';
time[6]++;
if((time[5]=='2')&&(time[6]=='4'))
for(i=5;i<13;i++)
{
if((i!=7)&&(i!=10))
time[i]='0';
}
else if(time[6]==':')
{
time[6]='0';
time[5]++;
}
}
}
}
}
j=0;
DisplayListChar(0,0,time);
}
ReadTemperature();
DisplayTemperature(t);
}
/**************************主函數定義****************************/
void main(void)
{
buzzer=1;
relay=1;
sub=1;
add=1;
esc=1;
ok=1;
// buzzer=0;
IE=0x82;
TMOD=0x01;
TF0=0;
TH0=0x3c;
TL0=0xb0; //T0初值設置
LCMInit(); //LCM初始化
DisplayListChar(0, 0, time);
TR0=1;
while(1)
{
if(sub==0)
{
buzzer=0;
Delay(5000);
buzzer=1;
Wait(0);
Wait(1);
}
if(add==0)
{
buzzer=0;
Delay(5000);
buzzer=1;
Wait(0);
Wait(1);
}
if(esc==0)
{
buzzer=0;
Delay(5000);
buzzer=1;
Wait(0);
Wait(1);
}
if(ok==0)
{
buzzer=0;
Delay(5000);
buzzer=1;
Wait(0);
Wait(1);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -