48 基于单片机的LCD12864时间调控和串口抱站

目录

一、主要功能

二、硬件资源

三、程序编程

四、实现现象


一、主要功能

**基于51单片机的公交报站系统,可以手动报站,站名十个。

在lcd12864上显示时间(年月日时分秒)和站名,时间可以设置,

仿真中可以语音播报。加一个用串口模拟语音播报。 **

二、硬件资源

基于KEIL5编写C++代码,PROTEUS8.15进行仿真,全部资源在页尾,提供安装包。

编辑

三、程序编程

#include <reg52.h>#include <intrins.h>#include<stdio.h>#include "DS1302.h"#include < character.h >#include < lcd.h >#define uchar unsigned char#define uint unsigned int
	unsigned char KEY\_NUM = 0;unsigned char KEY2\_Count = 0;
bit Flag\_KEY\_Set = 0;
sbit key1=P1^3;
sbit key2=P1^4;
sbit key3=P1^5;
sbit key4=P1^6;
sbit key5=P1^7;
sbit key6=P0^0;
sbit key7=P0^1;
sbit key8=P0^2;
sbit key9=P0^3;
sbit key10=P0^4;

sbit KEY1 = P0^5;
sbit KEY2 = P0^6;
sbit KEY3 = P0^7;
sbit KEY4 = P3^5;void ajpd();void jiemian1(void)  //站台一{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[2\]);  //
	printf("站台一\\r\\n");	
}void jiemian2(void)  //站台2{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[3\]);  //
	printf("站台二\\r\\n");	
}void jiemian3(void)  //站台3{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[4\]);  //
	printf("站台三\\r\\n");	
}void jiemian4(void)  //站台4{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[5\]);  //
	printf("站台四\\r\\n");	
}void jiemian5(void)  //站台5{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[6\]);  //
	printf("站台五\\r\\n");	
}void jiemian6(void)  //站台6{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[7\]);  //
	printf("站台六\\r\\n");	
}void jiemian7(void)  //站台7{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[8\]);  //
	printf("站台七\\r\\n");	
}void jiemian8(void)  //站台8{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[9\]);  //
	printf("站台八\\r\\n");	
}void jiemian9(void)  //站台9{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[10\]);  //
	printf("站台九\\r\\n");	
}void jiemian10(void)  //站台10{	Lcd\_Character\_16X16( 1, 4, 0 , function_logo\[0\]);  //
	Lcd\_Character\_16X16( 1, 4, 16 , function_logo\[1\]);  //
	Lcd\_Character\_16X16( 1, 4, 32 , function_logo\[11\]);  //
	printf("站台十\\r\\n");	
}//按键扫描程序//****************************************************void Scan_Key(){	if( KEY1 == 0 )	 					//按键1扫描
	{		Delay(10);					//延时去抖
		if( KEY1 == 0 )
		{			while(KEY1 == 0);			//等待松手
			KEY_NUM = 1;
		}
	}	if( KEY2 == 0 )						//按键2扫描
	{		Delay(10);					//延时去抖
		if( KEY2 == 0 )
		{			while(KEY2 == 0);			//等待松手
			KEY_NUM = 2;
		}
	}	if( KEY3 == 0 )						//按键2扫描
	{		Delay(10);					//延时去抖
		if( KEY3 == 0 )
		{			while(KEY3 == 0);			//等待松手
			KEY_NUM = 3;
		}
	}	if( KEY4 == 0 )						//按键2扫描
	{		Delay(10);					//延时去抖
		if( KEY4 == 0 )
		{			while(KEY4 == 0);			//等待松手
			KEY_NUM = 4;
		}
	}
}void Display\_RTCC(void){	Lcd\_Character\_16X8(1,0,0,letter\_logo\[DS1302Buffer.Year/10\]);	Lcd\_Character\_16X8(1,0,8,letter\_logo\[0\]);	Lcd\_Character\_16X8(1,0,16,letter\_logo\[2\]);	Lcd\_Character\_16X8(1,0,24,letter\_logo\[DS1302Buffer.Year%10\]);	Lcd\_Character\_16X8(1,0,32,letter\_logo\[11\]);	
  Lcd\_Character\_16X8(1,0,40,letter\_logo\[DS1302Buffer.Month/10\]);	Lcd\_Character\_16X8(1,0,48,letter\_logo\[DS1302Buffer.Month%10\]);	Lcd\_Character\_16X8(1,0,56,letter_logo\[11\]);	
	Lcd\_Character\_16X8(1,0,64,letter_logo\[DS1302Buffer.Day/10\]);	
	Lcd\_Character\_16X8(1,0,72,letter_logo\[DS1302Buffer.Day%10\]);	
	
	Lcd\_Character\_16X8(1,2,0,letter\_logo\[DS1302Buffer.Hour/10\]);	Lcd\_Character\_16X8(1,2,8,letter\_logo\[DS1302Buffer.Hour%10\]);	Lcd\_Character\_16X8(1,2,16,letter_logo\[10\]);	
	Lcd\_Character\_16X8(1,2,24,letter\_logo\[DS1302Buffer.Minute/10\]);	Lcd\_Character\_16X8(1,2,32,letter\_logo\[DS1302Buffer.Minute%10\]);	Lcd\_Character\_16X8(1,2,40,letter_logo\[10\]);	
	Lcd\_Character\_16X8(1,2,48,letter\_logo\[DS1302Buffer.Second/10\]);	Lcd\_Character\_16X8(1,2,56,letter\_logo\[DS1302Buffer.Second%10\]);
}//串口初始化void init_com(void){
 	TMOD =0x20;		   //设T0为方式1,GATE=1;
	SCON=0x50;        //开启串口
	TH1=0xFD;          //波特率是9600bps
	TL1=0xFD;
	TR1=1;			   //开启定时器
	TI=1;
	EA=1;
}void main(){	init\_com();	 Lcd\_Initial();     //LCD初始化
	 Lcd\_Display\_On();	//启动屏幕
	 DS1302_Init();									//初始化DS1302
    while(1)
    {	  DS1302_GetTime(&DS1302Buffer);							//获取当前RTCC值
	  if(Flag\_Time\_Refresh==1&& Flag\_KEY\_Set == 0)			//数据更新时才刷新LCD
		{
			Flag\_Time\_Refresh = 0;			Display_RTCC();				//显示实时时钟		
		}		ajpd();		
		Scan_Key();						//按键扫描
		
		switch( KEY_NUM )
		{			case 1:						//按键1执行程序
					KEY_NUM = 0;		//清空按键标志
					Flag\_KEY\_Set = ~Flag\_KEY\_Set;	//设置按键标志位翻转
					break;			case 2:						//按键2执行程序
					KEY_NUM = 0;		//清空按键标志
					if(Flag\_KEY\_Set)			//在设置状态时运行
					{
						KEY2\_Count++;						if(KEY2\_Count == 6)
							KEY2\_Count = 0;						switch(KEY2\_Count)
						{							case 0:									Lcd\_Set\_X_Y(0,0);	//指针指向年,闪烁
									break;							case 1:									Lcd\_Set\_X_Y(0,40);	//指针指向月,闪烁
									break;							case 2:									Lcd\_Set\_X_Y(0,64);	//指针指向日,闪烁
									break;							case 3:									Lcd\_Set\_X_Y(2,0);	//指针指向小时,闪烁
									break;							case 4:									Lcd\_Set\_X_Y(2,24);	//指针指向分钟,闪烁
									break;							case 5:									Lcd\_Set\_X_Y(2,48);	//指针指向秒钟,闪烁
									break;							default : break;
						}	
					}					
					break;			case 3:						//按键3执行程序
					KEY_NUM = 0;		//清空按键标志
					if(Flag\_KEY\_Set)			//在设置状态时运行
					{						switch(KEY2_Count)
						{							case 0:
									DS1302Buffer.Year++;									if(DS1302Buffer.Year >= 100)
									{
										DS1302Buffer.Year = 0;
									}									DS1302\_SetTime( DS1302\_YEAR , DS1302Buffer.Year );									Display_RTCC();									
									break;							case 1:
									DS1302Buffer.Month++;									if(DS1302Buffer.Month >= 13)
									{
										DS1302Buffer.Month = 1;
									}									DS1302\_SetTime( DS1302\_MONTH , DS1302Buffer.Month );									Display_RTCC();	
									break;							case 2:
									DS1302Buffer.Day++;									if(DS1302Buffer.Day >= 32)
									{
										DS1302Buffer.Day = 1;
									}									DS1302\_SetTime( DS1302\_DAY , DS1302Buffer.Day );									Display_RTCC();	
									break;							case 3:
									DS1302Buffer.Hour++;									if(DS1302Buffer.Hour >= 24)
									{
										DS1302Buffer.Hour = 0;
									}									DS1302\_SetTime( DS1302\_HOUR , DS1302Buffer.Hour );									Display_RTCC();									break;							case 4:
									DS1302Buffer.Minute++;									if(DS1302Buffer.Minute >= 60)
									{
										DS1302Buffer.Minute = 0;
									}									DS1302\_SetTime( DS1302\_MINUTE , DS1302Buffer.Minute );									Display_RTCC();	
							
									break;							case 5:
									DS1302Buffer.Second++;									if(DS1302Buffer.Second >= 60)
									{
										DS1302Buffer.Second = 0;
									}									DS1302\_SetTime( DS1302\_SECOND , DS1302Buffer.Second);									Display_RTCC();									break;							default : break;
						}
					}					break;			case 4:						//按键4执行程序
					KEY_NUM = 0;		//清空按键标志
					if(Flag\_KEY\_Set)			//在设置状态时运行
					{						switch(KEY2_Count)
						{							case 0:
									DS1302Buffer.Year--;									if(DS1302Buffer.Year == 255)
									{
										DS1302Buffer.Year = 99;
									}									DS1302\_SetTime( DS1302\_YEAR , DS1302Buffer.Year );									Display_RTCC();									
						
									break;							case 1:
									DS1302Buffer.Month--;									if(DS1302Buffer.Month == 0)
									{
										DS1302Buffer.Month = 12;
									}									DS1302\_SetTime( DS1302\_MONTH , DS1302Buffer.Month );									Display_RTCC();	
								
									break;							case 2:
									DS1302Buffer.Day--;									if(DS1302Buffer.Day == 0)
									{
										DS1302Buffer.Day = 31;
									}									DS1302\_SetTime( DS1302\_DAY , DS1302Buffer.Day );									Display_RTCC();	
									
									break;							case 3:
									DS1302Buffer.Hour--;									if(DS1302Buffer.Hour == 255)
									{
										DS1302Buffer.Hour = 23;
									}									DS1302\_SetTime( DS1302\_HOUR , DS1302Buffer.Hour );									Display_RTCC();	
									
									break;							case 4:
									DS1302Buffer.Minute--;									if(DS1302Buffer.Minute == 255)
									{
										DS1302Buffer.Minute = 59;
									}									DS1302\_SetTime( DS1302\_MINUTE , DS1302Buffer.Minute );									Display_RTCC();	
									
									break;							case 5:
									DS1302Buffer.Second--;									if(DS1302Buffer.Second == 255)
									{
										DS1302Buffer.Second = 59;
									}									DS1302\_SetTime( DS1302\_SECOND , DS1302Buffer.Second);									Display_RTCC();	
								
									break;							default : break;
						}
					}					break;			default : break;
		}				
    }
}void ajpd(){	if(!key1)
	{		jiemian1();		while(!key1);
	}	
	if(!key2)
	{		jiemian2();		while(!key2);
	}	
	if(!key3)
	{		jiemian3();		while(!key3);
	}	
	if(!key4)
	{		jiemian4();		while(!key4);
	}	
	if(!key5)
	{		jiemian5();		while(!key5);
	}	
	if(!key6)
	{		jiemian6();		while(!key6);
	}	
	if(!key7)
	{		jiemian7();		while(!key7);
	}	
	if(!key8)
	{		jiemian8();		while(!key8);
	}	
	if(!key9)
	{		jiemian9();		while(!key9);
	}	
	if(!key10)
	{		jiemian10();		while(!key10);
	}
}

四、实现现象

具体动态效果看B站演示视频:

48-基于单片机的LCD12864时间调控和串口抱站_哔哩哔哩_bilibili

全部资料(源程序、仿真文件、安装包、演示视频):

点击下载百度网盘资料

相关推荐
牧以南歌〆2 小时前
STM32模拟I2C通讯的驱动程序
c语言·stm32·单片机·嵌入式硬件
whaosoft-1436 小时前
51c嵌入式~单片机~合集2
嵌入式硬件
嵌入式小章6 小时前
基于 STM32 的电池管理系统
stm32·单片机·嵌入式硬件
夜间看花6 小时前
47 基于单片机的书库环境监测
单片机·嵌入式硬件
weixin_1122336 小时前
基于单片机的智能灯光控制系统
单片机·嵌入式硬件
平凡灵感码头7 小时前
STM32 了解OLED
stm32·单片机·嵌入式硬件
电子绿洲10 小时前
深度解析:RTC电路上的32.768KHz时钟的频偏及测试
单片机·嵌入式硬件·学习·硬件工程·实时音视频·信息与通信·智能硬件
just a little bit!11 小时前
电阻功率,限流,等效电阻
嵌入式硬件
银科院-计算机与人工智能13 小时前
单片机原理级应用 笔记
笔记·单片机