本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
我用DS12887和6位数码管做个电子钟,数码管动态怎么读DS12887里面的数据呢,代码如下,仿真显示数码管是不亮的,求各位大神帮助,帮看看显示部分有什么问题吗,或者其他部分有什么问题,下星期一要交作品了,有些着急,谢谢了。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char yi,wan,qian,bai,shi,ge,hour,minute,second;
sbit dula=P3^7;
sbit wela=P3^6;
sbit dscs=P2^4;
sbit dsas=P2^5;
sbit dsrw=P2^6;
sbit dsds=P2^7;
sbit dsirq=P3^3;
void display(uchar yi,uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void delay(uint z) //延时1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_ds(uchar add,uchar date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P1=add;
dsas=0;
dsrw=0;
P1=date;
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P1=add;
dsas=0;
dsds=0;
P1=0xff;
ds_date=P1;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void init() //初始化
{
EA=1;
EX0=1;
IT0=1;
dula=0;
wela=0;
}
void set_time()
{
write_ds(4,0);
write_ds(2,0);
}
void main()
{
init();
set_time();
while(1)
{
display();
delay(10);
}
}
void display(uchar yi,uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
second=read_ds(0);
minute=read_ds(2);
hour=read_ds(4);
ge=second%10;
shi=second/10;
bai=minute%10;
qian=minute/10;
wan=hour%10;
yi=hour/10;
dula=1;
P0=table[yi];
dula=0;
P0=0xff;
wela=1;
P0=0x01;
wela=0;
delay(1);
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0x02;
wela=0;
delay(1);
dula=1;
P0=table[qian];
dula=0;
P0=0x04;
wela=1;
P0=0xdf;
wela=0;
delay(1);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0x08;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0x10;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0x20;
wela=0;
delay(1);
}
|
|