标题:
LCD1602 LM016L+DS1302显示时间(Proteus仿真+代码)
[打印本页]
作者:
张无
时间:
2019-3-12 09:02
标题:
LCD1602 LM016L+DS1302显示时间(Proteus仿真+代码)
无按键操作
# 元器件
LCD1602的元器件是LM016L
# 文件介绍
除了未测试文件夹下的代码不能使用,其它三份都可以在仿真图上使用。
ds1302+lcd1602_1:摘抄自仿真图链接中的代码;
ds1302+lcd1602_2:是对仿真图链接代码的分解版本;
my1302:是修改过的版本,按照需要条件,可以加入别的项目直接调用;
未测试:忘了是从哪摘抄的了,没有对应得仿真图,无法测试。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png
(11.5 KB, 下载次数: 70)
下载附件
2019-3-12 15:38 上传
单片机源程序如下:
/*
时间:2019/01/30 11:47
*/
/*
51单片机:DS1302+LCD1602 Proteus 仿真程序。
功能:LCD1602时钟与日期的显示。
仿真结果:LCD1602显示设定的时间与日期。
*/
#include <reg52.h>
#include "ds1302.h"
/**********LCD1602接口程序**********/
#define LCD_PORT P1//液晶LCD1602数据
sbit RS = P2^4;
sbit RW = P2^5;
sbit E= P2^6;
bit ReadRTC_Flag; //读DS1302标志。1为读 0为不读。
unsigned char time_buf1[7] = {34,2,16,23,59,50,7}; // 年月日时分秒周 2014-02-16 23:59:50 7周
unsigned char time_buf[7] ;
char data str1[16]="Date: ? ?";
char data str2[16]="Time: ? ?";
void InitTIMER0(void);//inital timer0
// LCD1602函数声明
void Delay_1ms(unsigned char i);
void Delay_10us(unsigned char i);
void Write_Cmd(unsigned char cmd);
void Write_Dat(unsigned char dat);
void Addr_x_y(unsigned char x,bit y);
void Show_Char(unsigned char x,bit y,unsigned char p);
void Show_String(unsigned char x,bit y,char *ptr);
void LCD_Init(void);
void main(void)
{
LCD_Init();
DS1302_Init();
DS1302_Write_Time();
InitTIMER0();
//P2=0xff; ? //51默认为输入
while(1)
{
if(ReadRTC_Flag==1)
{
ReadRTC_Flag=0;
DS1302_Read_Time();
}
str1[5]=time_buf1[0]/10 + '0'; //年 数据的转换,
str1[6]=time_buf1[0]%10 + '0'; //因我们采用数码管0~9的显示,将数据分开
str1[7]=0x2d; //加入"-"
str1[8]=time_buf1[1]/10 + '0'; //月
str1[9]=time_buf1[1]%10 + '0';
str1[10]=0x2d;
str1[11]=time_buf1[2]/10 + '0'; //日
str1[12]=time_buf1[2]%10 + '0';
str1[13]=0x20;
str1[14]='W';
str1[15]=time_buf1[6] + '0'; //周几
str2[5]=time_buf1[3]/10 + '0'; //时 数据的转换,
str2[6]=time_buf1[3]%10 + '0'; //因我们采用数码管0~9的显示,将数据分开
str2[7]=0x3a;//加入"-"
str2[8]=time_buf1[4]/10 + '0'; //分
str2[9]=time_buf1[4]%10 + '0';
str2[10]=0x3a;
str2[11]=time_buf1[5]/10 + '0'; //秒
str2[12]=time_buf1[5]%10 + '0';
Show_String(0,0,str1);
Show_String(0,1,str2);
}
}
/********************************/
void Delay_1ms(unsigned char i) //最小延时1ms
{
unsigned char j;
while(i--)
;
for(j=0;j<125;j++)
;
}
void Delay_10us(unsigned char i) //最小延时10us
{
unsigned char j;
while(i--)
for(j=0;j<10; j++)
;
}
void Write_Cmd(unsigned char cmd)//写指令
{
Delay_10us(5);
E=0;
RS=0;
RW=0;
LCD_PORT=cmd;
Delay_10us(5); //>40us
E=1;
Delay_1ms(2); //>150us
E=0;
Delay_10us(4); //>25+10us?
}
void Write_Dat(unsigned char dat) //写数据
{
Delay_10us(5);
E=0;
RS=1;
RW=0;
LCD_PORT = dat;
Delay_10us(5);
E=1;
Delay_10us(5);
E=0;
Delay_10us(4);
}
void Addr_x_y(unsigned char x,bit y) //写坐标,定位置
{
unsigned char temp=0x80; //默认最高位:D7为1 即以0x80开始。 ?
if(y) //y :0为第一行 ?1为第二行
{
temp|=0x40;
}
temp|=x;
Write_Cmd(temp);
}
void Show_Char(unsigned char x,bit y,unsigned char p)
//在指定位置显示一个字符。
{
Addr_x_y(x,y);
Write_Dat(p);
}
void Show_String(unsigned char x,bit y,char *ptr)
{
unsigned char i;
for (i=0;i<16;i++)
Show_Char(x++,y,*(ptr+i));//循环显示16个字符
}
void LCD_Init(void) //1602初始化代码
{
Delay_1ms(1500);
Write_Cmd(0x38);
Delay_1ms(5);
Write_Cmd(0x38);
Delay_1ms(5);
Write_Cmd(0x38);
Delay_1ms(5);
Write_Cmd(0x38);
Write_Cmd(0x08);
Write_Cmd(0x06);
Write_Cmd(0x0c);
Write_Cmd(0x01);
}
/*------------------------------------------------
? ? ? ? ? ?Timer0 初始化,开中断,2ms定时
------------------------------------------------*/
void InitTIMER0(void)
{
TMOD|=0x01; //定时器设置 16位
TH0=(65536-2000)/256; //定时时间 ? 2ms
TL0=(65536-2000)%256;
EA=1;
ET0=1;
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
LCD1602+DS1302-201903110942.zip
(38.62 KB, 下载次数: 102)
2019-3-12 09:01 上传
点击文件名下载附件
显示时间
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1