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

📄 time.c

📁 测温db18b20 液晶1602 显示时间和温度
💻 C
字号:
#include<reg52.h>
#include<Text2.h>
#define uchar unsigned char
#define uint unsigned int

sbit lcden=P3^4;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
sbit rd=P3^1;
sbit s1=P3^7;
sbit s2=P3^6;


uchar code table1[]="2008-10-05"; uchar code table2[]="18:20:00";
 
uchar i; uchar count=0;	uchar miao,fen,shi;
uchar wei;




void write_date(uchar a)
{
	lcden=0;
	lcdrs=1;
	P0=a;
	lcden=1;
	delay(2);
	lcden=0;
	delay(2);
}
void write_com(uchar a)
{
	lcden=0;
	lcdrs=0;
	P0=a;
	lcden=1;
	delay(2);
	lcden=0;
	delay(2);
}
void init()
{
	dula=0;
	wela=0;
	write_com(0x38);
	write_com(0x0c);
	write_com(0x06);
	write_com(0x01);
	write_com(0x80+1);
	for(i=0;i<10;i++)
	{
		write_date(table1[i]);
		delay(10);
	}  
	write_com(0x80+14);
	write_date(0xdf);write_date(0x43);
	write_com(0x80+0x40+4);
	for(i=0;i<8;i++)
	{
		write_date(table2[i]);
		delay(10);
	}
	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	EA=1;
	ET0=1;
	TR0=1; 


}

void write_time(uchar address,uchar date)
{
	uchar shi,ge;
	shi=date/10;
	ge=date%10;
	write_com(0x80+0x40+4+address);
	write_date(0x30+shi);
	write_date(0x30+ge);
}
void write_wendu(uchar address,uchar date)
{
	uchar bai,shi,ge;
	bai=date/100;
	shi=date%100/10;
	ge=date%10;
	write_com(0x80+address);
	//write_date(0x30+bai);
	write_date(0x30+shi);
	write_date(0x30+ge);
}

void keyscan()
{
	rd=0;
	if(s1==0)
	{
		delay(5);
		if(s1==0)
		{
			while(!s1);
			wei++;
			if(wei==1)
			{
				TR0=0;
				write_com(0x0f);
				write_com(0x80+0x40+10);
			}
			if(wei==2)
			{
				write_com(0x80+0x40+7);
			}
			if(wei==3)
			{
				write_com(0x80+0x40+4);
			}
			if(wei==4)
			{
				wei=0;
				write_com(0x0c);
				TR0=1;
			}

		}
	}
	if(wei!=0)
		{
			if(s2==0)
			{
				delay(5);
				if(s2==0)
				{
					while(!s2);
					if(wei==1)
					{
						miao++;
						if(miao==60)miao=0;
						write_time(6,miao);write_com(0x80+0x40+10);
					}
					if(wei==2)
					{
						fen++;
						if(fen==60)fen=0;
						write_time(3,fen);write_com(0x80+0x40+7);
					}
					if(wei==3)
					{
						shi++;
						if(shi==24)shi=0;
						write_time(0,shi);write_com(0x80+0x40+4);
					}
					
				}
			}
		}	
	
}


void main()
{
	init();
   
	
	while(1)
	{
		

		keyscan();

	};			 
	

}

void timer() interrupt 1
{
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	count++;
	if(count==18)
	{	
		count=0;
		miao++;
		if(miao==60)
		{
			miao=0;
			fen++;
			if(fen==60)
			{
				fen=0;
				shi++;
				if(shi==24)shi=0;
				write_time(0,shi);
			}
			write_time(3,fen);
		}
		write_time(6,miao);
	}
			 wenconvert();
		 
	write_wendu(12,wenrdtemp());
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -