⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a.c

📁 单片机的小车需
💻 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 + -