没有合适的资源?快使用搜索试试~ 我知道了~
单片机C语言电子钟显示年月日星期及时间(带注释).doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2022-07-02
23:21:33
上传
评论 1
收藏 105KB DOC 举报
温馨提示
试读
16页
单片机C语言电子钟显示年月日星期及时间(带注释)
资源推荐
资源详情
资源评论
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=" 2011-12-30 SAT";
uchar code table1[]=" 23:59:55 ";
uchar code week1[][3]={"MON","TUE","WEN","THU","FRI","SAT","SUN"};
/*uchar code week2[]="TUE";
uchar code week3[]="WEN";
uchar code week4[]="THU";
uchar code week5[]="FRI";
uchar code week6[]="SAT";
uchar code week7[]="SUN"; */
uchar count,shi,fen,miao,dnum,year,month,day,week,a=5;
sbit rs=P2^0; //数据命令
sbit rw=P2^1; //读写
sbit en=P2^2; //使能
sbit d1=P3^1; //独立键盘
sbit d2=P3^2;
sbit d3=P3^3;
sbit d4=P3^4;
void delay(uchar z) //延时
{
uint x,y;
for(x=110;x>0;x--)
for(y=z;z>0;z--);
}
void write_com(uchar com) //写指令
{
rs=0;
rw=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void write_date(uchar date) //写数据
{
rs=1;
rw=0;
en=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
}
void write_weekday (uchar a)
{
uchar x;
write_com(0x80+13);
for(x=0;x<3;x++)
{
write_date(week1[a][x]);
}
}
void weekday(uint i)
{
write_weekday(i%7);
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add); //指向要写的地址
write_date(0x30+shi); //0x30 代表的数字是 0,+shi 表示 shi 的数字
write_date(0x30+ge); //ge 的数字
}
void write_ymd(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add); //指向要写的地址
write_date(0x30+shi); //0x30 代表的数字是 0,+shi 表示 shi 的数字
write_date(0x30+ge); //ge 的数字
}
void unit()
{
uchar num;
en=0;
write_com(0x38); //显示
write_com(0x0c); //光标不显示
write_com(0x06); //指针加 1,整屏不移动
write_com(0x01); //清屏
write_com(0x80); //指针指向 0x80
for(num=0;num<16;num++) //第一行显示 table 数组
{
write_date(table[num]);
delay(20);
}
write_com(0x80+0x40);
for(num=0;num<16;num++) //第二行显示 table1 数组
{
write_date(table1[num]);
delay(20);
}
TMOD=0X01;
TH0=(65536-50000)/256; //开启中断
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
shi=23;
fen=59;
miao=55;
year=11;
month=12;
day=30;
}
void jishu() //计数
{
if(count==20)
{
count=0;
miao++; //秒加
if(miao==60)
{
miao=0;
fen++; //分加
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
day++;
a++;
weekday(a);
//时加
}
write_sfm(3,shi);
write_ymd(9,day);
if(day==31)
{
day=0x01;
write_ymd(9,day);
month++;
write_ymd(6,month);
if(month==13)
{
month=0x01;
write_ymd(6,month);
year++;
write_ymd(3,year);
}
}
}
write_sfm(6,fen);
}
write_sfm(9,miao);
}
}
void change()
{
d4=0;
剩余15页未读,继续阅读
资源评论
oligaga
- 粉丝: 50
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功