找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

单片机1602液晶显示调时时钟为什么光标不能闪烁?高手给点指点

[复制链接]
admin 发表于 2012-9-2 12:21:31 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include <reg52.h>
#define unint unsigned int
#define unchar unsigned char
void delay(unint a);
void write_data(unchar b);
void write_com(unchar c);
void init();
void write_sfm(unchar add,unchar date);
unchar code table1[]=" 2010-10-30";
unchar code table2[]=" 00:00:00";
sbit lcdrs=P2^5;
sbit lcdrw=P2^6;
sbit lcden=P2^7;
sbit ky1=P1^0;
sbit ky2=P1^1;
sbit ky3=P1^2;
sbit ky=P1^7;
void keyscan();
unint aa;
void main()
{
unint shi,fen,miao;
init();
while(1)
{
keyscan();
if(aa==20)
{
aa=0;
miao++;
if(miao==60)
{
miao=0;
fen++;

if(fen==60)
{
fen=0;
shi++;

if(shi==24)
{
shi=0;
}
}
write_sfm(3,shi);
}
write_sfm(6,fen);
}
write_sfm(9,miao);
}
}


void write_data(unchar b)
{
lcdrs=1;
P0=b;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_com(unchar c)
{
lcdrs=0;
P0=c;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
unint num;
lcden=0;
lcdrw=0;
write_com(0x38);
write_com(0x0f);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<11;num++)
{
write_data(table1[num]);
delay(2);
}
write_com(0x80+0x40);
for(num=0;num<11;num++)
{
write_data(table2[num]);
delay(2);
}
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(unint a)
{
unint i,j;
for(i=a;i>0;i--)
for(j=110;j>0;j--);
}
void write_sfm(unchar add,unchar date)
{
unint shi,fen;
shi=date/10;
fen=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+fen);

}
void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;

}
void keyscan()
{
unchar ky1num;
ky=0;
if(ky1==0)
{
delay(5);
if(ky1==0)
{
ky1num++;

}
while(!ky1);
if(ky1num==1)
{
TR0=0;
write_com(0x80+0x40+10);
write_com(0x0f);
}
if(ky1num==2)
{
write_com(0x80+0x40+7);
}
if(ky1num==3)
{
write_com(0x80+0x40+4);
}
if(ky1num==4)
{
ky1num=0;
TR0=1;
write_com(0x0c);
}
}

}


*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 23:03 , Processed in 0.061806 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表