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

📄 lcd12864.c

📁 12864液晶显示多功能电子时钟
💻 C
📖 第 1 页 / 共 2 页
字号:
 	write_clock(0x8e,0x00);
//	write_clock(0x80,0x80);
	write_clock(0x90,0x00);
	write_clock(0x8c,year);//_nop_();
	write_clock(0x8a,week);//_nop_();
	write_clock(0x88,mon);//_nop_();
	write_clock(0x86,day);//_nop_();
	write_clock(0x84,hour);//_nop_();
	write_clock(0x82,min);//_nop_();
	write_clock(0x80,sec);
//	write_clock(0x90,0xa5);//_nop_();
	write_clock(0x8e,0x80);
}
 	


/*按键控制程序段*/
sbit KeyHL =P1^3;  //左上
sbit KeyBL =P1^4;   //左下
sbit KeyBR =P1^5;  //右下
sbit KeyHR =P1^6;   //右上
sbit KeyGas = P1^7; //煤气报警控制
unsigned char adjust=1,add_or_dec, type=0x01 ;
void update(void);


unsigned char  BCD_Coverter(unsigned char dd)
{
	unsigned char temp;
	temp=dd;
	temp=temp/10;
	dd=(dd%10)|(temp<<4);
	return dd;
}
void adjust_year(void)
{
	if(year>=0&&year<=99&&add_or_dec==1) year++;
	if(year==100&&add_or_dec==1) year=0;
	if(year==0x00&&add_or_dec==0) year=100;
	if(year>0x00&&year<=100&&add_or_dec==0) year--;
	
	LCD_WriteData(5,1,year/10+0x30);
	LCD_data(year%10+0x30);

}
void adjust_mon(void)
{
	
	if(mon>=1&&mon<=12&&add_or_dec==1) mon++;
	if(mon==13&&add_or_dec==1) mon=1;
	if(mon>=1&&mon<=12&&add_or_dec==0) mon--;
	if(mon==0&&add_or_dec==0) mon=12;
	LCD_WriteData(5,2,mon/10+0x30);
	LCD_data(mon%10+0x30);

}
void adjust_day(void)
{
	unsigned char day_max;
	
	if(mon==2)
	{
	if(year%4==0)
	{
		if(year%100!=0) day_max=29;
		else if(year%400==0)day_max=29;
		else day_max=28;
	}
	else day_max=28;
	}
	else if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12) day_max=31;
    else day_max=30;
	if(day>=1&&day<=day_max&&add_or_dec==1) day++;
	if(day==(day_max+1)&&add_or_dec==1) day=1;
	if(day>=1&&day<=day_max&&add_or_dec==0) day--;
	if(day==0&&add_or_dec==0) day=day_max;
	LCD_WriteData(7,2,day/10+0x30);
	LCD_data(day%10+0x30);	

}

void adjust_hour(void)
{
	
	if(hour>=0&&hour<=23&&add_or_dec==1) hour++;
	if(hour==24&&add_or_dec==1) hour=0;
	if(hour==0&&add_or_dec==0) hour=24;
	if(hour>0&&hour<=24&&add_or_dec==0) hour--;
	LCD_WriteData(1,3,hour/10+0x30);
	LCD_data(hour%10+0x30);
	

}
void adjust_min(void)
{	
	if(min>=0&&min<=59&&add_or_dec==1) min++;
	if(min==60&&add_or_dec==1) min=0;
	if(min==0&&add_or_dec==0) min=60;
	if(min>0&&min<=60&&add_or_dec==0) min--;

	LCD_WriteData(2,3,0x3a);
	LCD_data(min/10+0x30);
	LCD_data(min%10+0x30);

}
void adjust_week(void)
{
	
	if(week>=1&&week<=7&&add_or_dec==1) week++;
	if(week==8&add_or_dec==1) week=1;
	if(week>=1&&week<=7&&add_or_dec==0) week--;
	if(week==0&&add_or_dec==0) week=7;
	LCD_Week();
}
void adjust_time(void)
{

	LCD_WriteStr(1,1,"[Esc]");
	LCD_WriteStr(6,1,"[NEXT]");
	LCD_WriteStr(1,4,"[+] 调整年份 [-]");
	while(KeyHL==0);
	delay(1000);
	while(adjust==1)
	{

	if(KeyHL==0)
	{
		delay(1000);
		if(KeyHL==0)adjust=0;
	}


	if(KeyBL==0)
	{
		delay(1000);
		add_or_dec=1;  //加操作
		switch(type)
		{
			case 1: adjust_year();break;
			case 2: adjust_mon(); break;
			case 3: adjust_day(); break;
			case 4: adjust_hour(); break;
			case 5: adjust_min(); break;
			case 6: adjust_week(); break;
			default:break;
		}
	//	update();
		while(KeyBL==0);	
		delay(1000);		 
	}
	

	if(KeyBR==0)
	{
		delay(1000);
		add_or_dec=0;    //减操 作
		switch(type)
		{
			case 1: adjust_year();break;
			case 2: adjust_mon(); break;
			case 3: adjust_day(); break;
			case 4: adjust_hour();break;
			case 5: adjust_min(); break;
			case 6: adjust_week(); break;
			default:break;
		}
	//	update();
		while(KeyBR==0);
		delay(1000);
		
	}

	if(KeyHR==0)
	{
		delay(1000);
		if(type==6)type=0;
		 type++;
			if(type==1) {LCD_WriteStr(1,4,"[+] 调整年份 [-]");}
		    if(type==2) {LCD_WriteStr(1,4,"[+] 调整月份 [-]"); }
			if(type==3) {LCD_WriteStr(1,4,"[+] 调整日份 [-]");}
		    if(type==4) {LCD_WriteStr(1,4,"[+] 调整小时 [-]");}
			if(type==5) {LCD_WriteStr(1,4,"[+] 调整分钟 [-]"); }
			if(type==6) {LCD_WriteStr(1,4,"[+] 调整星期 [-]"); }
			
	    while(KeyHR==0);
		delay(1000);
		
		
	}


	}
	adjust=1;
	type=0x01;
	LCD_WriteStr(1,1,"[Dis]      [Set]");
	year=BCD_Coverter(year);
	day=BCD_Coverter(day);
	hour=BCD_Coverter(hour);
	min=BCD_Coverter(min);
	sec=BCD_Coverter(sec);
	write_clocks();
	update();
}

void KeyCheck(void)
{
//	unsigned char temp;
	if(KeyHL==0) 
	{
		delay(1000);
		if(KeyHL==0) 
		{
			write_clock(0x8e,0x00);
			write_clock(0x80,0x80);
			write_clock(0x8e,0x80);
			adjust_time();
		 }
	}
}

			


void LCD_Week(void)
{
	switch(week)
	{
		case 1:LCD_WriteStr(8,3,"一");break;
		case 2:LCD_WriteStr(8,3,"二");break;
		case 3:LCD_WriteStr(8,3,"三");break;
		case 4:LCD_WriteStr(8,3,"四");break;
		case 5:LCD_WriteStr(8,3,"五");break;
		case 6:LCD_WriteStr(8,3,"六");break;
		case 7:LCD_WriteStr(8,3,"日");break;
	 }
}


  void days (viod)
	{	  //公历节日数据库
		
		unsigned char m=0;

		if ( mon == 0x01 && day == 1 ){ LCD_WriteStr(1,4,"Happy New Year!!"); m=1;}//1月
		if ( mon == 0x01 && day == 28 ){ LCD_WriteStr(1,4,"  世界麻风日    ");m=1; }
		
		if ( mon == 0x02 && day == 0x02 ){ LCD_WriteStr(1,4,"  世界湿地日    "); m=1;}//2月
		if ( mon == 0x02 && day == 13 ){ LCD_WriteStr(1,4,"  明天情人节了  "); m=1;}		
		if ( mon == 0x02 && day == 14 ){ LCD_WriteStr(1,4,"  今天是情人节  "); m=1;}
				
		if ( mon == 0x03 && day == 0x01 ){ LCD_WriteStr(1,4,"  国际海豹日    "); m=1;}//3月		
		if ( mon == 0x03 && day == 0x03 ){ LCD_WriteStr(1,4,"  全国爱耳日    "); m=1;}		
		if ( mon == 0x03 && day == 0x08 ){ LCD_WriteStr(1,4,"   3.8妇女节    "); m=1;}		
		if ( mon == 0x03 && day == 12 ){ LCD_WriteStr(1,4,"    植树节      "); m=1;}		
		if ( mon == 0x03 && day == 14 ){ LCD_WriteStr(1,4,"  国际警察日    "); m=1;}		
		if ( mon == 0x03 && day == 15 ){ LCD_WriteStr(1,4,"  消费者权益日  "); m=1;}		
		if ( mon == 0x03 && day == 17 ){ LCD_WriteStr(1,4,"  国际航海日    "); m=1;}		
		if ( mon == 0x03 && day == 21 ){ LCD_WriteStr(1,4,"  世界森林日    "); m=1;}		
		if ( mon == 0x03 && day == 22 ){ LCD_WriteStr(1,4,"    世界水日    "); m=1;}		
		if ( mon == 0x03 && day == 23 ){ LCD_WriteStr(1,4,"  世界气象日    "); m=1;}		
		if ( mon == 0x03 && day == 24 ){ LCD_WriteStr(1,4,"世界防治结核病日"); m=1;}
				
		if ( mon == 0x04 && day == 0x01 ){ LCD_WriteStr(1,4,"愚人节  小心上当"); m=1;}//4		
		if ( mon == 0x04 && day == 0x07 ){ LCD_WriteStr(1,4,"  世界卫生日    ");m=1; }		
		if ( mon == 0x04 && day == 0x08 ){ LCD_WriteStr(1,4,"    复活节      ");m=1; }		
		if ( mon == 0x04 && day == 13 ){ LCD_WriteStr(1,4,"  黑色星期五    ");m=1;}
				
		if ( mon == 0x05 && day == 0x01 ){ LCD_WriteStr(1,4,"  劳动节  放假  "); m=1;}//5		
		if ( mon == 0x05 && day == 4 ){ LCD_WriteStr(1,4,"    青年节      ");m=1;}		
		if ( mon == 0x05 && day == 0x08 ){ LCD_WriteStr(1,4,"  世界红十字日  "); m=1;}		
		if ( mon == 0x05 && day == 12 ){ LCD_WriteStr(1,4,"  国际护士节    "); m=1;}		
		if ( mon == 0x05 && day == 0x05 ){ LCD_WriteStr(1,4,"近日注意母亲节  "); m=1;}		
		if ( mon == 0x05 && day == 15 ){ LCD_WriteStr(1,4,"  国际家庭日    "); m=1;}
		if ( mon == 0x05 && day == 31 ){ LCD_WriteStr(1,4,"  世界无烟日    ");m=1; }		
				
		if ( mon == 0x06 && day == 0x01 ){ LCD_WriteStr(1,4,"  国际儿童节    "); m=1;}//6
		if ( mon == 0x06 && day == 0x05 ){ LCD_WriteStr(1,4,"  世界环境日    "); m=1;}		
		if ( mon == 0x06 && day == 26 ){ LCD_WriteStr(1,4,"  国际禁毒日    "); m=1;}		
		if ( mon == 0x06 && day == 0x06 ){ LCD_WriteStr(1,4,"  全国爱眼日    "); m=1;}		
		if ( mon == 0x06 && day == 13 ){ LCD_WriteStr(1,4,"近日注意父亲节  "); m=1;}
		if ( mon == 0x06 && day == 15 ){ LCD_WriteStr(1,4,"近日注意父亲节  "); m=1;}
				
		if ( mon == 0x07 && day == 0x01 ){ LCD_WriteStr(1,4,"香港回归记念日  ");m=1; }//7
		if ( mon == 0x07 && day == 0x07 ){ LCD_WriteStr(1,4,"抗日战争记念日  "); m=1;}
		if ( mon == 0x07 && day == 11 ){ LCD_WriteStr(1,4,"  世界人口日    "); m=1;}

		if ( mon == 0x08 && day == 0x01 ){ LCD_WriteStr(1,4,"  八一建军节    "); m=1;}//8
		if ( mon == 0x08 && day == 0x08 ){ LCD_WriteStr(1,4,"  中国男子节    "); m=1;}
		if ( mon == 0x08 && day== 15 ){ LCD_WriteStr(1,4,"抗战胜利记念日  "); m=1;}

		if ( mon == 0x09 && day == 10 ){ LCD_WriteStr(1,4,"  中国教师节    ");m=1; }//9
		if ( mon == 0x09 && day == 18 ){LCD_WriteStr(1,4,"九·一八事变记念");m=1; }
		if ( mon == 0x09 && day == 20 ){ LCD_WriteStr(1,4,"  国际爱牙日    "); m=1;}
		if ( mon == 0x09 && day == 27 ){ LCD_WriteStr(1,4,"  世界旅游日    "); m=1;}

		if ( mon == 10 && day == 1 ){ LCD_WriteStr(1,4,"  中国国庆节    "); m=1;}//10
		if ( mon == 10 && day == 4 ){ LCD_WriteStr(1,4,"  世界动物日    "); m=1;}
		if ( mon == 10 && day == 24 ){ LCD_WriteStr(1,4,"    联合国日    "); m=1;}
		if ( mon == 10 && day == 12 ){ LCD_WriteStr(1,4,"明天国际教师节  ");m=1; }
		if ( mon == 10 && day == 13 ){ LCD_WriteStr(1,4,"  国际教师节    "); m=1;}

		if ( mon == 11 && day == 10 ){ LCD_WriteStr(1,4,"  世界青年节    ");m=1; }//11
		if ( mon == 11 && week == 4 && day >= 22 && day <= 28){ LCD_WriteStr(1,4,"  今天感恩节    ");m=1;}
		if ( mon == 11 && day == 17 ){ LCD_WriteStr(1,4,"  世界学生节    "); m=1;}

		if ( mon == 12 && day == 1 ){ LCD_WriteStr(1,4,"  世界艾滋病日  "); m=1;}//12
		if ( mon == 12 && day == 23 ){ LCD_WriteStr(1,4,"  明晚平安夜    "); m=1;}
		if ( mon == 12 && day == 24 ){ LCD_WriteStr(1,4,"  今晚平安夜    "); m=1;}
		if ( mon == 12 && day == 25 ){ LCD_WriteStr(1,4,"    圣诞快乐    "); m=1;}
		if ( mon == 12 && day == 31 ){ LCD_WriteStr(1,4,"    明日新年    "); m=1;}

		if(m==0)
		{ 
			if ( hour >= 0x04 && hour <  0x06 ){ LCD_WriteStr(1,4,"★★__▲▲__凌晨"); }
			if ( hour >= 0x06 && hour <  0x08 ){ LCD_WriteStr(1,4,"☆○__▲△__早晨"); }
			if ( hour >= 0x08 && hour <  12 ){ LCD_WriteStr(1,4,"__●__▲▲__上午"); }
			if ( hour == 12)               { LCD_WriteStr(1,4,"____▲●▲__中午"); }
			if ( hour >= 13 && hour <  18 ){ LCD_WriteStr(1,4,"__▲▲__●__下午"); }
			if ( hour >= 18 && hour <  22 ){ LCD_WriteStr(1,4,"△▲__●☆__晚上"); }
			if ( hour >= 22 && hour <= 23 ){ LCD_WriteStr(1,4,"△▲__★☆__夜里"); }
			if ( hour >= 0x00 && hour <  0x04 ){ LCD_WriteStr(1,4,"__★▲▲★__深夜"); }
		}
}
void update(void)
{	
	unsigned char hour_temp;
	hour_temp=hour;
	read_clocks();
	if(hour_temp==23&&hour==4)
	{
		write_clock(0x8e,0x00);
		write_clock(0x84,0x00);
		write_clock(0x8e,0x80);
	 }
	 read_clocks();
//	year=read_clock(0x8d);
//	if(0x00<=year&&year<=0x99)
//	{
	LCD_WriteStr(4,1,"20");
	LCD_data((year/10)+0x30);
	LCD_data((year%10)+0x30);
//	}
//	mon=read_clock(0x89);
	//if(mon>=0x01&&mon<=0x12)
//	{
	LCD_WriteData(5,2,mon/10+0x30);
	LCD_data(mon%10+0x30);
	LCD_WriteStr(6,2,"月");
//	}

//	day=read_clock(0x87);
//	if(day>=0x00&&day<=0x31)
//	{
	LCD_WriteData(7,2,day/10+0x30);
	LCD_data(day%10+0x30);
	LCD_WriteStr(8,2,"日");
//	}
	
//	min=read_clock(0x83);
//	hour=read_clock(0x85);
//	hour=read_clock(0x85);
	
	
//	if(hour>=0x00&&hour<=0x24)
//	{
	LCD_WriteData(1,3,(hour/10)+0x30);
	LCD_data((hour%10)+0x30);
//	}

	LCD_data(0x3a);
	

	
//	if(min>=0x00&&min<=0x59)
//	{

	LCD_data((min/10)+0x30);
	LCD_data((min%10)+0x30);
//	}

	LCD_data(0x3a);
	LCD_WriteStr(6,3,"星期");
//	week=read_clock(0x8b);
	LCD_Week();
	
//	if(sec==0x00) update();
//LCD_WriteData(4,3,(sec/16)+0x30);
//	LCD_data((sec%16)+0x30);
	days();
 }
	
void main()
{

	LCD_init();
	init_1302();
	getTemValue();		//ds18b20初始化

  //EX0=1;		//开外部中断
//	EA=1;
	power=1;
	LCD_WriteStr(1,1,"[Dis]      [Set]");
	
	update();
	while(1)
	{
	KeyCheck();
	sec=read_clock(0x81);

//	if(0x00<=sec&&sec<=0x59)
//	{
	if(sec==0x00) update();
	LCD_WriteData(4,3,(sec/10)+0x30);
	LCD_data((sec%10)+0x30);
//	}



	getTemValue();
	TEMP_BUFF[0]=TMPH/10+0x30;
	TEMP_BUFF[1]=TMPH%10+0x30;
	TEMP_BUFF[2]='.';
	TEMP_BUFF[3]=TMPL+0x30;
	TEMP_BUFF[4]='\0';
	LCD_WriteStr(1,2,&TEMP_BUFF);
	LCD_WriteStr(3,2,"℃");
	}
	
}
/*void  gas_int(void)  interrupt 0
{
	EX0 =0;
	Beep = 0;
	power = 1;
	LCD_WriteStr(1,2,"   有煤气!   ");
	delay(1000);
	Beep = 1;
	delay(1000);
	EX0 = 1;
}*/



⌨️ 快捷键说明

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