- 2
- 0
- 约6.78千字
- 约 7页
- 2015-08-23 发布于河南
- 举报
#include?reg52.h ??
#define?uint?unsigned?int ??
#define?uchar?unsigned?char ??
??
sbit?lcdrs?=?P1^0; ??
sbit?lcdrw?=?P1^1; ??
sbit?lcden?=?P1^2; ??
??
sbit?key0?=?P2^0;//功能键,选择时分秒 ??
sbit?key1?=?P2^1;//加1键 ??
sbit?key2?=?P2^2;//减1键 ??
sbit?key4?=?P2^4; ??
??
uchar?key0_count;//按键0被按的次数(0~3) ??
??
char?hour,minute,second;?//时分秒 ??
uint?timer_count;??//定时器中断计数 ??
??
uchar?table_date[]?=?2009-4-12??Mon; ??
uchar?table_time[]?=?00:00:00; ??
??
/******?函数申明?********/??
void?write_cmd_1602(uchar?cmd); ??
void?write_data_1602(uchar?dat); ??
void?write_add(uchar?add,uchar?dat); ??
void?init1602(); ??
void?delay(uint?z); ??
uchar?reverse(uchar?c); ??
void?keyscan(); ??
void?init(); ??
/******?主函数?********/??
void?main() ??
{ ??
????init(); ??
????//init1602(); ??
????//while(1); ??
????while(1) ??
????{ ??
????????keyscan(); ??
????????delay(5); ??
????} ??
} ??
//1602液晶初始化 ??
void?init1602() ??
{ ??
????lcdrw?=?0;?????????????//本程序只读不写,故将其置低 ??
????lcden?=?0;?????????????//关闭1602 ??
????delay(5); ??
????write_cmd_1602(0x01);??//清屏 ??
????write_cmd_1602(0x38);??//显示模式 ??
????write_cmd_1602(0x0c);??//开显示,不显示光标,不闪烁 ??
????write_cmd_1602(0x06);??//地址指针自动加1 ??
????write_cmd_1602(0x80+1);//将光标指向第一行第二个位置 ??
????delay(5); ??
} ??
void?delay(uint?z) ??
{ ??
????uint?x,y; ??
????for(x=z;x0;x--) ??
????????for(y=110;y0;y--); ??
} ??
/**?将发送的数据进行翻转,高位到低位,低位转到高位?**/??? ??
uchar?reverse(uchar?c)??? ??
{??? ??
???uchar?chbuff=0;??? ??
???if?(c0x01)?chbuff=chbuff|0x80;??? ??
???if?(c0x02)?chbuff=chbuff|0x40;??? ??
???if?(c0x04)?chbuff=chbuff|0x20;??? ??
???if?(c0x08)?chbuff=chbuff|0x10;??? ??
???if?(c0x10)?chbuff=chbuff|0x08;??? ??
???if?(c0x20)?chbuff=chbuff|0x04;??? ??
???if?(c0x40)?chbuff=chbuff|0x02;??? ??
???if?(c0x80)?chbuff=chbuff|0x01;??? ??
???return?chbuff;??? ??
} ??
//向液晶写命令 ??
void?write_cmd_1602(uchar?cmd) ??
{ ??
????lcdrs?=?0;?//低表示写命令,高表示写数据 ??
????delay(5); ??
????P0?=?reverse(cmd); ??
????delay(5); ??
????lcden?=?1;?//给一个高脉冲 ??
????delay(5);??? ??
????lcden?=?0; ??
????
您可能关注的文档
最近下载
- 新解读《DL_T 408—2023电力安全工作规程 发电厂和变电站电气部分》最新解读.docx VIP
- 1.7 有多少名观众 教案 2025-2026学年北师大版数学三年级下册.docx VIP
- 第5章 比亚迪精诚钣喷质量管理体系(A0版).pdf VIP
- 学堂在线《大学生心理健康》课后作业单元考核答案.docx VIP
- 脑出血钻孔引流术后护理要点.pptx VIP
- 抖音美妆类短视频营销策略.pdf VIP
- 热敏罐灸疗法可复制.pdf VIP
- 《过敏性紫癜预防与处理指南(2025)解读》.docx VIP
- SL706-2015水库调度编制导则.pdf VIP
- 《美妆短视频的发展问题研究》文献综述1700字.docx VIP
原创力文档

文档评论(0)