以下是源程序 不显示时钟 反而仅在第一行的指定位置显示“85 85 85” 请问怎么回事 因为调这个程序搞的我心烦意乱 我把全部15积分的家当都拿来了
/**************************************************
**************************************************/
#include<reg52.h>
#define uchar unsigned char
//-----DS1302-------------
#define WRITE_SECOND 0x80
#define WRITE_MINUTE 0x82
#define WRITE_HOUR 0x84
#define READ_SECOND 0x81
#define READ_MINUTE 0x83
#define READ_HOUR 0x85
#define WRITE_PROTECT 0x8E
sbit rs=P2^6;//1602数据指令选择
sbit rw=P2^5;//1602读写控制
sbit e=P2^7; //1602使能端
sbit sclk=P3^6;//1302时钟信号
sbit ce=P3^5; //1302使能端
sbit dsio=P3^7;//1302IO口
sbit ACC_7=ACC^7;
uchar i,temp,shi,fen,miao;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_cmd(uchar cmd) //1602写指令函数
{
rs=0;
rw=0;
e=0;
P0=cmd;
delay(1);
e=1;
delay(1);
e=0;
}
void write_dat(uchar dat) //1602写数据函数
{
rs=1;
rw=0;
e=0;
P0=dat;
delay(1);
e=1;
delay(1);
e=0;
}
void write_1302(uchar addr,uchar dat)
{
uchar temp,k;
ce=0;
sclk=0;
ce=1;
for(k=0;k<8;k++)
{
sclk=0;
temp=addr;
dsio=(bit)(temp&0x01);
sclk=1;
addr=addr>>1;
}
for(k=0;k<8;k++)
{
sclk=0;
temp=dat;
dsio=(bit)(temp&0x01);
sclk=1;
dat=dat>>1;
}
ce=0;
}
uchar read_1302(uchar addr)
{
uchar k,temp,dat,dat1;
ce=0;
sclk=0;
ce=1;
for(k=0;k<8;k++)
{
sclk=0;
temp=addr;
dsio=(bit)(temp&0x01);
sclk=1;
addr=addr>>1;
}
for(k=0;k<8;k++)
{
sclk=1;
ACC_7=dsio;
sclk=0;
ACC=ACC>>1;
}
ce=0;
dat1=ACC; //BCD码转换为十进制数
dat=10*(dat1/16)+(dat1%16);
return dat;
}
void init_lcd() //初始化函数
{
rs=0;
rw=0;
e=0;
delay(1);
write_cmd(0x06);
write_cmd(0x0c); //光标显示设置
write_cmd(0x38);
write_cmd(0x01);//清屏
}
void init_1302()
{
write_1302(WRITE_PROTECT,0X00);
write_1302(WRITE_SECOND,0X31);
write_1302(WRITE_MINUTE,0X21);
write_1302(WRITE_HOUR,0X11);
}
void write_sfm(uchar add,uchar dat) //往1602中写数据(即时间)
{
uchar shi,ge;
shi=dat/10;
ge=dat%10;
write_cmd(0x80+add);
write_dat(0x30+shi);
write_dat(0x30+ge);
}
void main()
{
init_lcd();
init_1302();
while(1)
{
miao=read_1302(READ_SECOND);
fen=read_1302(READ_MINUTE);
shi=read_1302(READ_HOUR);
write_sfm(10,miao);
write_sfm(7,fen);
write_sfm(4,shi);
}
} |