#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit duan=P2^6;
sbit wei=P2^7;
sbit dat=P2^0;
sbit clock=P2^1;
sbit rs=P2^4;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
uchar shu,shu1,sec1,sec2,fen1,fen2,shi1,shi2,temp;
uchar sec,fen,shi;
uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
void delay(uchar z);
void write_byte(uchar c,uchar shuju);
uchar read_byte(uchar m);
void write(uchar date)
{
uchar i;
ACC=date;
for(i=8;i>0;i--)
{
dat=ACC0;
clock=0;
clock=1;
ACC=ACC>>1;
}
}
uchar read()
{
uchar i;
for(i=8;i>0;i--)
{
dat=ACC7;
clock=1;
clock=0;
ACC=ACC>>1;
}
return ACC;
}
void write_byte(uchar c,uchar shuju)
{
clock=0;
rs=0;
rs=1;
write(c);
write(shuju);
delay(20);
clock=1;
rs=0;
}
uchar read_byte(uchar m)
{
clock=0;
rs=0;
rs=1;
write(m|0x01);
shu1=read();
delay(20);
clock=1;
rs=0;
return shu1;
}
void delay(uchar z)
{
uchar a;
for(a=z;a--;a>0);
}
void ints()
{
duan=0;
wei=0;
write_byte(0x8e,0x00);
write_byte(0x80,0x01);
write_byte(0x82,0x20);
write_byte(0x84,0x15);
write_byte(0x8e,0x80); }
void dvid()
{
sec=read_byte(0x81);
sec1=(sec&0x0f);
sec2=(sec>>4);
fen=read_byte(0x83);
fen1=(fen&0x0f);
fen2=(fen>>4);
shi=read_byte(0x85);
shi1=(shi&0x0f);
shi2=(shi>>4);
}
void display()
{
wei=1;
P0=0xfe;
wei=0;
P0=0;
duan=1;
P0=num[sec1];
duan=0;
delay(5);
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
P0=0;
duan=1;
P0=num[sec2];
duan=0;
delay(5);
P0=0xff;
wei=1;
P0=0xfb;
wei=0;
P0=0;
duan=1;
P0=num[fen1];
duan=0;
delay(5);
P0=0xff;
wei=1;
P0=0xf7;
wei=0;
P0=0;
duan=1;
P0=num[fen2];
duan=0;
delay(5);
P0=0xff;
wei=1;
P0=0xef;
wei=0;
P0=0;
duan=1;
P0=num[shi1];
duan=0;
delay(5);
P0=0xff;
wei=1;
P0=0xdf;
wei=0;
P0=0;
duan=1;
P0=num[shi2];
duan=0;
delay(5);
}
void main()
{
ints();
while(1)
{
P1=read();
display();
}
}我写的是一个关于用DS1302
芯片做一个时钟在数码管上显示的,不知什么原因在
单片机上显示初值0后不再变化,求给我指一下程序的错误!!!谢谢啊
这么点程序,尽量还是自己发现问题,对自己的提高有帮助。
一周热门 更多>