不用时钟芯片,写的时钟,可是。。。
51单片机吧
全部回复
仅看楼主
level 4
可是编译出来 秒正常显示 ,分为58时直接跳到01,时不动? 这是什么问题? 代码 感觉没问题啊? 帮我看下大神们
2015年05月19日 13点05分 1
level 4
代码怎么没了
2015年05月19日 14点05分 3
level 4
#include<reg52.h>
#include<intrins.h>
sbit RW=P2^4;
sbit RS=P2^3;
sbit E=P2^5;
#define uchar unsigned char
#define uint unsigned int
uchar num,count;
void delay(uint i);
uchar code table[]=" 2015-5-19 MON";
uchar code table1[]=" 20:58:55";
uchar shi,miao,fen;
void write_com(uchar com) //写指令
{
RS=0;
RW=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
}
void write_date(uchar date)//写数据
{
RS=1;
RW=0;
P0=date;
delay(5);
E=1;
delay(5);
E=0;
}
void write_sfm(uchar add ,uchar date) //写返回的数据
{
uchar sw,gw;
sw=0;
gw=0;
sw=date/10;
gw=date%10;
write_com(0xc0+add);
write_date(0x30+sw);
write_date(0x30+gw);
}
void init()//初始化
{
// miao=0;
// shi=0;
// fen=0;
count=0;
write_com(0x38); /*显示模式设置*/
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0xC0);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0X01; //定时器0
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
}
//延时函数
void delay(uint i)
{
uint j,k;
for(j=i;j>0;j--)
for(k=110;k>0;k--);
}
void main() //主函数
{
init();
while(1)
{
if(count==20)
{
count=0;
miao++;
if(miao>59)
{
miao=0;
fen++;
if(fen>59)
{
fen=0;
shi++;
if(shi>23)
{
shi=0;
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
//while(1);
}
}
void intep1() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}
2015年05月19日 14点05分 4
level 4
别删代码啊
2015年05月19日 14点05分 5
1