




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、lcd1602液晶显示电子时钟(lcd1602 liquid crystal display electronic clock)lcd1602 liquid crystal display electronic clockheroes and heroes, happy new year!i learn c language soon today to write a clock program, found when debugging, manual adjustment is completely normal, but in the automatic time, date and w
2、eek is inconsistent with the facts, please help me, thank you, the following source program#include <at89x52.h>#define uchar unsigned char#define uint unsigned intsbit rs=p20;sbit rw=p21;sbit lcden=p22;sbit s1=p15;sbit s2=p16;sbit s3=p17;uchar, count, s1num;char, miao, shi, fen, w, r, y, a;uch
3、ar code table= "2009-01-29 w4""uchar code table1= "00:00:00""void delay (uint z) / / delay proceduresuint, x, y;for (x=z; x>0; x-)for (y=110; y>0; y-);void write_com (uchar com) / / write commands to the 1602 lcdrw=0;rs=0;lcden=0;p0=com;delay (5);lcden=1;delay (5)
4、;lcden=0;void write_date (uchar date) / / write data to the 1602 lcdrw=0;rs=1;lcden=0;p0=date;delay (5);lcden=1;delay (5);lcden=0;void (init) / / initializeuchar num;lcden=0;write_com (0x38); / / set the display modewrite_com (0x0c); / / open displaywrite_com (0x06); / / when writing time automatic
5、plus 1write_com (0x01); / / screen displaywrite_com (0x80); / / pointer data setfor (num=0; num<15; num+) / / set the first line digital positionwrite_date (tablenum); / / the first line of digital displaydelay (5);write_com (0x80+0x40); / / set the next display second linesfor (num=0; num<12;
6、 num+) / / set the second row positionwrite_date (table1num); / / digital display second linesdelay (5);tmod=0x01; / / set the timer function 1th0= (65536-50000 /256); / / timer initial loadingtl0= (65536-50000)%256;ea=1; / / open interruptet0=1; / / t0 timer interrupttr0=1; / / start timervoid writ
7、e_sfm (uchar add, uchar date) when the separation / /uchar shi, ge; / / set a bit, ten bit variableshi=date/10; / / from tenge=date%10; / / from awrite_com (0x80+0x40+add); / / locationwrite_date (0x30+shi); / / the ten bit datawrite_date (0x30+ge); / / a bit datavoid write_r (uchar, add, uchar, dat
8、e)uchar ge; / / set a bitge=date;write_com (0x80+add); / / locationwrite_date (0x30+ge); / / a bit datavoid write_ny (uchar add, uchar date) when the separation / /uchar shi, ge; / / set a bit, ten bit variableshi=date/10; / / from tenge=date%10; / / from awrite_com (0x80+add); / / locationwrite_dat
9、e (0x30+shi); / / the ten bit datawrite_date (0x30+ge); / / a bit datavoid (keyscan) / / keyscanif (s1=0) / / if the s1 key is presseddelay (5); / / xiaodouif (s1=0) / / again confirming whether a key is pressed, the execution of programs1num+;while (s1!); / / determine whether the s1 key up,if lift
10、ed, enter the set stateif (s1num=1) / / if this number is 1, the implementation of programtr0=0; / / shutdown timerwrite_com (0x80+0x40+10); / / set the cursor in the second positionwrite_com (0x0f); / / set the light and flashing displayif (s1num=2) / / if this number is 2, the implementation of pr
11、ogramwrite_com (0x80+0x40+7); / / set the cursor in the positionif (s1num=3) / / if this number is 3, the implementation of programwrite_com (0x80+0x40+4); / / set the cursor in the positionif (s1num=4) / / if this number is 4, the implementation of programwrite_com (0x80+14); / / set the cursor pos
12、ition in the weekif (s1num=5) / / if this number is 5, the implementation of programwrite_com (0x80+9); / / set the cursor position on the dateif (s1num=6) / / if this number is 6, the implementation of programwrite_com (0x80+6); / / set the cursor position in the monthif (s1num=7) / / if this numbe
13、r is 7, the implementation of programwrite_com (0x80+3); / / set the cursor position in the yearif (s1num=8) / / if this number is 8, exit the setting states1num=0; / / the number zerowrite_com (0x0c); / / close cursortr0=1; / / start timer, travel timeif (s1num! =0) / / if this number is not 0, the
14、n enter the adjustment plus or minus keyif (s2=0) to confirm whether a key is pressed.delay (5); / / xiaodouif (s2=0) / / again confirming whether a key is pressedwhile (s2!); / / determine whether the s1 key is lifted, if lifted, enter the set state numberif (s1num=1) / / determine the set position
15、 is in secondsmiao+;if (miao=60) is applied to the 60 / /miao=0; / / resetwrite_sfm (10, miao); / / refreshwrite_com (0x80+0x40+10);if (s1num=2)fen+;if (fen=60)fen=0;write_sfm (7, fen);write_com (0x80+0x40+7);if (s1num=3)shi+;if (shi=24)shi=0;write_sfm (4, shi);write_com (0x80+0x40+4);if (s1num=4) /
16、 / determine the set position is in the weekw+;if (w=7) is applied to the 7 / /w=0; / / zhou qinglingwrite_r (14, w); / / refreshwrite_com (0x80+14);if (s1num=5) / / determine the set position is in the dayr+;if (r=32) is applied to the 31 / /r=1; / / day 1write_ny (9, r); / / refreshwrite_com (0x80
17、+9);if (s1num=6) / / determine the set position is in juney+;if (y=13) is applied to the 12 / /y=1; / / seigetsuwrite_ny (6, y); / / refreshwrite_com (0x80+6);if (s1num=7) / / determine the set position is in the yeara+;if (a=100) is applied to the 99 / /a=0; / / year zerowrite_ny (3, a); / / refres
18、hwrite_com (0x80+3);if (s3=0)delay (5);if (s3=0)while (. s3);if (s1num=1)miao-;if (miao=-1)miao=59;write_sfm (10, miao);write_com (0x80+0x40+10);if (s1num=2)fen-;if (fen=-1)fen=59;write_sfm (7, fen);write_com (0x80+0x40+7);if (s1num=3)shi-;if (shi=-1)shi=23;write_sfm (4, shi);write_com (0x80+0x40+4)
19、;if (s1num=4)w-;if (w=-1)w=6;write_r (14, w); / / refreshwrite_com (0x80+14);if (s1num=5) / / determine the set position is in the dayr-;if (r=0)r=31;write_ny (9, r); / / refreshwrite_com (0x80+9);if (s1num=6) / / determine the set position is in juney-;if (y=0)y = 12;write _ ny (6 / refresh the display, y).write _ com (0x80 + 6);if (s1num = = 7)sub -.if (a = = 0)a =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 水沟项目工程方案
- 大学之道的考试题及答案
- 湖南省农业农村厅直属事业单位招聘考试真题2025
- 2025风水咨询服务合同
- 2025商品房买卖合同模板
- 合伙众筹协议书范本
- 中国漂白凝胶项目商业计划书
- 急救证考试试题及答案
- 机械员考试试题及答案2025
- 居间协议书 违约金 20
- 第2单元第6课《认识操作系统桌面》课件 【甘少版】《信息科技》四年级上册
- 2024-2025学年陕西省西安市碑林区部分学校北师大版四年级上册期中测试数学试卷(含答案)
- 2025年及未来5年中国电梯维保行业市场前景预测及投资战略研究报告
- 生成式人工智能培训
- 2025年高考真题分类汇编必修三 《政治与法治》(全国)(解析版)
- 机器学习原理及应用课件:回归分析
- 手绘植物花卉课件
- 土耳其移民合同范本
- 执法员压力与情绪管理课件
- (2025)营养指导员考试真题库(含答案)
- 小升初道法复习课件
评论
0/150
提交评论