/*******************************************************************/
//Name of this design: LCD show Electric Clock
//Author: Huangxiang
//Date: 2008-12-21
//proteus仿真论坛:proteus.5d6d.com
/*******************************************************************/
#include <reg51.h>
#include <intrins.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
#define BUSY 0x80 //lcd忙检测标志
#define DATAPORT P0 //定义P0口为LCD通讯端口
sbit light=P1^3;
sbit LCM_RS=P2^0; //数据/命令端
sbit LCM_RW=P2^1; //读/写选择端
sbit LCM_EN=P2^2;
uchar second; //定义并初始化时钟变量
uchar minite;
uchar hour;
uchar mstcnt=0;
uchar t,set=0;
uchar code str0[]={"DATE :2008-12-21"};
uchar code str1[]={"TIME : : : "};
void delay_LCM(uint); //LCD延时子程序
void initLCM( void); //LCD初始化子程序
void lcd_wait(void); //LCD检测忙子程序
void WriteCommandLCM(uchar WCLCM,uchar BusyC); //写指令到ICM子函数
void WriteDataLCM(uchar WDLCM); //写数据到LCM子函数
void DisplayOneChar(uchar X,uchar Y,uchar DData); //显示指定坐标的一个字符子函数
void DisplayListChar(uchar X,uchar Y,uchar code *DData); //显示指定坐标的一串字符子函数
void init_timer0(void); //定时器初始化
void displayfun1(void);
void displayfun2(void);
void displayfun3(void);
void keyscan(void ); //键盘扫描子程序
void set_adj(void);
void inc_key(void);
void dec_key(void);
/*********延时K*1ms,12.000mhz**********/
void delay_LCM(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<60;j++)
{;}
}
}
/**********写指令到LCM子函数************/
void WriteCommandLCM(uchar WCLCM,uchar BusyC)
{
if(BusyC)lcd_wait();
DATAPORT=WCLCM;
LCM_RS=0; // 选中指令寄存器
LCM_RW=0; // 写模式
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
/**********写数据到LCM子函数************/
void WriteDataLCM(uchar WDLCM)
{
lcd_wait( ); //检测忙信号
DATAPORT=WDLCM;
LCM_RS=1; // 选中数据寄存器
LCM_RW=0; // 写模式
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
/***********lcm内部等待函数*************/
void lcd_wait(void)
{
DATAPORT=0xff;
LCM_EN=1;
LCM_RS=0;
LCM_RW=1;
_nop_();
while(DATAPORT&BUSY)
{ LCM_EN=0;
_nop_();
_nop_();
LCM_EN=1;
_nop_();
_nop_();
}
LCM_EN=0;
}
/**********LCM初始化子函数***********/
void initLCM( )
{
DATAPORT=0;
delay_LCM(15);
WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,1); //8bit数据传送,2行显示,5*7字型,检测忙信号
WriteCommandLCM(0x08,1); //关闭显示,检测忙信号
WriteCommandLCM(0x01,1); //清屏,检测忙信号
WriteCommandLCM(0x06,1); //显示光标右移设置,检测忙信号
WriteCommandLCM(0x0c,1); //显示屏打开,光标不显示,不闪烁,检测忙信号
}
/****************显示指定坐标的一个字符子函数*************/
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)X|=0x40; //若y为1(显示第二行),地址码+0X40
X|=0x80; //指令码为地址码+0X80
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
/***********显示指定坐标的一串字符子函数***********/
void DisplayListChar(uchar X,uchar Y,uchar code *DData)
{
uchar ListLength=0;
Y&=0x01;
X&=0x0f;
while(X<16)
{
DisplayOneChar(X,Y,DData[ListLength]);
ListLength++;
X++;
}
}
/***************液晶显示子函数1正常显示*****************/
void displayfun1(void)
{
WriteCommandLCM(0x0c,1); //显示屏打开,光标不显示,不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
DisplayOneChar(7,1,hour/10+0x30); //液晶上显示小时
DisplayOneChar(8,1,hour%10+0x30);
DisplayOneChar(10,1,minite/10+0x30); //液晶上显示分
DisplayOneChar(11,1,minite%10+0x30);
DisplayOneChar(13,1,second/10+0x30); //液晶上显示秒
DisplayOneChar(14,1,second%10+0x30);
}
/************液晶显示子函数2***************/
void displayfun3(void)
{
WriteCommandLCM(0x0c,1); //显示屏打开,光标不显示,不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
DisplayOneChar(7,1,hour/10+0x30);
DisplayOneChar(8,1,hour%10+0x30);
DisplayOneChar(13,1,second/10+0x30);
DisplayOneChar(14,1,second%10+0x30);
WriteCommandLCM(0x0f,1); //显示屏打开,光标显示,闪烁,检测忙信号
DisplayOneChar(10,1,minite/10+0x30);
DisplayOneChar(11,1,minite%10+0x30);
}
/**************液晶显示子函数3*****************/
void displayfun2(void)
{
WriteCommandLCM(0x0c,1); //显示屏打开,光标不显示,不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
DisplayOneChar(10,1,minite/10+0x30);
DisplayOneChar(11,1,minite%10+0x30);
DisplayOneChar(13,1,second/10+0x30);
DisplayOneChar(14,1,second%10+0x30);
WriteCommandLCM(0x0f,1); //显示屏打开,光标显示,闪烁,检测忙信号
DisplayOneChar(7,1,hour/10+0x30);
DisplayOneChar(8,1,hour%10+0x30);
}
/**************键盘扫描子函数******************/
void keyscan(void)
{
uchar xx; //局部变量
P1=0xff;
if(P1!=0xff)
{
delay_LCM(50);
if(P1!=0xff)
{
xx=P1;
switch(xx) // 根据按键状态,调用不同的子函数
{
case 0xfe:set_adj();
break;
case 0xfd:inc_key();
break;
case 0xfb:dec_key();
break;
default:
break;
}
}
}
}
/**************设定工作模式子函数****************/
void set_adj(void)
{
delay_LCM(100);
set++;
if(set>2)
set=0;
}
/****************按键加法子函数******************/
void inc_key(void)
{
delay_LCM(150);
if(set==1)
{
hour++;
if(hour>=23)
hour=23;
}
else
if(set==2)
{
minite++;
if(minite>=59)
minite=59;
}
else
displayfun1();
}
/****************按键减法子函数*****************/
void dec_key(void)
{
delay_LCM(150);
if(set==1)
{
hour--;
if(hour<=0)
hour=0;
}
else
if(set==2)
{
minite--;
if(minite<=0)
minite=0;
}
else
displayfun1();
}
/***************定时器t0初始化*******************/
void init_timer0(void)
{
TMOD=0x01; //time0为定时器,方式1
TH0=0x3c; //预置计数初值
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
}
/***********定时器t0中断子函数**************/
void timer0(void) interrupt 1 using 0 //定时器0方式1,50ms中断一次
{
TH0=0x3c;
TL0=0xb0;
mstcnt++;
if(mstcnt>=20 )
{
second++;
mstcnt=0;
}
if(second>=60)
{
minite++;
second=0;
}
if(minite>=60)
{
hour++;
minite=0;
light=0;
delay_LCM(200);
light=1;
}
if(hour>=24)
没有合适的资源?快使用搜索试试~ 我知道了~
LCD1602yejingxianshi.rar_Simulation passed !_protues_yejingxians
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共15个文件
bak:2个
液晶显示电子时钟1:1个
opt:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 147 浏览量
2022-09-24
14:48:26
上传
评论
收藏 59KB RAR 举报
温馨提示
很全面的一款用lcd1602实现的电子钟,protues仿真通过了,大家放心使用。
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 15 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/fca2fc36c4174e7caf12f1c9ba2c9265_weixin_42657024.jpg!1)
邓凌佳
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)