这是程序,不知带为什么用protues仿真都显示5,求教
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define M 1
sbit sp=P3^0;
sbit dscs=P2^4;
sbit dsas=P2^5;
sbit dsrw=P2^6;
sbit dsds=P2^7;
sbit duan=P2^0;
sbit wei=P2^1;
sbit k1=P3^4;
sbit k2=P3^5;
sbit k3=P3^6;
sbit k4=P3^7;
void delay(uint);
void init();
void display_sfm(uchar,uchar,uchar);
void display_nyr(uchar,uchar,uchar);
void write_ds(uchar,uchar);
void set_time();
uchar read_ds(uchar);
uchar shi,fen,miao,month,day;
uchar year,num1,num2,num3,num4,num5,num6;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
write_ds(0x0a,0x20);
write_ds(0x0b,0x26);
set_time();
}
void display_sfm(uchar sh,uchar fe,uchar mia)
{
uchar sg,ss,fg,fs,mg,ms;
sg=sh%10;
ss=sh/10;
fg=fe%10;
fs=fe/10;
mg=mia%10;
ms=mia/10;
duan=1;
P0=table[ss];
duan=0;
P0=0xfe;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[sg];
duan=0;
P0=0xfd;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[10];
duan=0;
P0=0xfb;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[fs];
duan=0;
P0=0xf7;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[fg];
duan=0;
P0=0xef;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[10];
duan=0;
P0=0xdf;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[ms];
duan=0;
P0=0xbf;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[mg];
duan=0;
P0=0x7f;
wei=1;
wei=0;
P0=0x00;
delay(M);
}
void display_nyr(uchar yea,uchar mon,uchar sec)
{
uchar sg,ss,fg,fs,mg,ms;
sg=yea%10;
ss=yea%100/10;
fg=mon%10;
fs=mon/10;
mg=sec%10;
ms=sec/10;
duan=1;
P0=table[ss];
duan=0;
P0=0xfe;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[sg];
duan=0;
P0=0xfd;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[10];
duan=0;
P0=0xfb;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[fs];
duan=0;
P0=0xf7;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[fg];
duan=0;
P0=0xef;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[10];
duan=0;
P0=0xdf;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[ms];
duan=0;
P0=0xbf;
wei=1;
wei=0;
P0=0x00;
delay(M);
duan=1;
P0=table[mg];
duan=0;
P0=0x7f;
wei=1;
wei=0;
P0=0x00;
delay(M);
}
void write_ds(uchar add,uchar date)
{
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P1=add;
dsas=0;
dsrw=0;
P1=date;
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P1=add;
dsas=0;
dsds=0;
P1=0xff;
ds_date=P1;
dsas=1;
dsds=1;
dscs=1;
return ds_date;
}
void set_time()
{
write_ds(0,0);
write_ds(1,0);
write_ds(2,0);
write_ds(3,0);
write_ds(4,0);
write_ds(5,0);
write_ds(6,0);
write_ds(7,0);
write_ds(8,0);
write_ds(9,0);
}
void main()
{
init();
while(1)
{
year=read_ds(9);
month=read_ds(8);
day=read_ds(7);
shi=read_ds(4);
fen=read_ds(2);
miao=read_ds(0);
display_nyr(year,month,day);
}
}
|