想请问下,为什么下面这个程序烧进单片机里面为什么不是显示11?
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit acc0=ACC^0;
sbit acc7=ACC^7;
sbit led1=P0^4;
sbit led2=P0^5;
sbit res=P2^0;
sbit sclk=P2^1;
sbit io=P2^2;
void delay(uint m)
{
uint i,j;
for(i=m;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint num)
{
uchar ge,shi;
shi=num/10;
ge=num%10;
P0=ge;
led1=1;
led2=0;
delay(10);
led2=1;
P0=shi;
led1=0;
delay(10);
led1=1;
}
typedef struct _time{
uchar sec;
uchar min;
uchar hour;
uchar day;
uchar mon;
uchar year;
}time;
uchar rd_byte()
{
uint i;
for(i=8;i>0;i--)
{
ACC=ACC>>1;
acc7=io;
sclk=1;
sclk=0;
}
return(ACC);
}
void wr_byte(uchar d)
{
uint i;
ACC=d;
for(i=8;i>0;i--)
{
io=acc0;
sclk=1;
sclk=0;
ACC=ACC>>1;
}
}
void write(uchar add,uchar dat)
{
res=0;
sclk=0;
res=1;
wr_byte(add);
wr_byte(dat);
sclk=1;
res=0;
}
uchar read(uchar add)
{
uchar dat;
res=0;
sclk=0;
res=1;
wr_byte(add);
dat=rd_byte();
sclk=1;
res=0;
return(dat);
}
void set_time(uchar add,uchar dat)
{
write(0x8e,0x00);
write(add,((dat/10)<<4|(dat%10)));
}
void get_time(time *tim)
{
uchar rd_dat;
rd_dat=read(0x81);
tim->sec=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
rd_dat=read(0x83);
tim->min=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
rd_dat=read(0x85);
tim->hour=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
rd_dat=read(0x87);
tim->day=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
rd_dat=read(0x89);
tim->mon=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
rd_dat=read(0x8d);
tim->year=((rd_dat&0x70)>>4)*10 + (rd_dat&0x0F);
}
void init()
{
set_time(0x80,40);
set_time(0x82,30);
set_time(0x84,11);
set_time(0x86,7);
set_time(0x88,4);
set_time(0x8C,11);
}
void main()
{
time* t;
init();
get_time(t);
while(1)
{
display(t->year);
}
}
|