程序问题,求教了T_T

2019-07-15 18:56发布

显示的不是设定的初始值,反而一直显示2010-00-00 0
00-00-00
#include<reg51.h>
#include<intrins.h>
#define LCD1602 P0
sbit LCD_RS=P2^6;
sbit LCD_RW=P2^5;
sbit LCD_E=P2^7;
sbit CE=P3^5;
sbit SCLK=P3^6;
sbit DSIO=P3^4;
unsigned char write_addr[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
unsigned char read_addr[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
unsigned char tiME[7]={0x00,0x40,0x15,0x01,0x08,0x05,0x14};
void Delay1us(unsigned int a)
{
unsigned int b,c;
for(c=a;c>0;c--)
for(b=110;b>0;b--);
}
void LCD1602writecom(unsigned char com)
{ LCD_E=0;
LCD_RS=0;
LCD_RW=0;
LCD1602=com;
LCD_E=1;
Delay1us(10);
LCD_E=0;
Delay1us(10);
}
void LCD1602writedat(unsigned char dat)
{
LCD_E=0;
LCD_RS=1;
LCD_RW=0;
LCD1602=dat;
LCD_E=1;
Delay1us(10);
LCD_E=0;
Delay1us(10);
}
void LCD1602init()
{
LCD1602writecom(0x38);
LCD1602writecom(0x0c);
LCD1602writecom(0x06);
LCD1602writecom(0x01);
}

void DS1302write(unsigned char addr,unsigned char dat)
{
unsigned int n;
SCLK=0;
Delay1us(10);
CE=1;
Delay1us(10);
for(n=0;n>8;n++)
{
DSIO=addr&0x01;
addr=_cror_(addr,1);
SCLK=1;
Delay1us(10);
SCLK=0;
Delay1us(10);
}
for(n=0;n>8;n++)
{
DSIO=dat&0x01;
dat=_cror_(dat,1);
SCLK=1;
Delay1us(10);
SCLK=0;
Delay1us(10);
}
}
unsigned char DS1302read(unsigned char addr)
{
unsigned char n,dat,dat1;
SCLK=0;
Delay1us(10);
CE=1;
Delay1us(10);
for(n=0;n>8;n++)
{
DSIO=addr&0x01;
addr=_cror_(addr,1);
SCLK=1;
Delay1us(10);
SCLK=0;
Delay1us(10);
}
for(n=0;n>8;n++)
{

dat1=DSIO;
dat=_cror_(dat,1);
dat=_crol_(dat,7);
SCLK=1;
Delay1us(10);
SCLK=0;
Delay1us(10);
}
return dat;
}
void DS1302init()
{
unsigned char n;
DS1302write(0x8E,0x00);
for(n=0;n<7;n++)
{
DS1302write(write_addr[n],TIME[n]);
}
DS1302write(0x8E,0x80);
}
void DS1302readtime()
{
unsigned char n;
for(n=0;n<7;n++)
{
TIME[n]=DS1302read(read_addr[n]);
}
}
void LCDdisplay()
{
LCD1602writecom(0x80+0x40);
LCD1602writedat(*0*+TIME[2]/16);
LCD1602writedat(*0*+(TIME[2]&0x0f));
LCD1602writedat(*-*);
LCD1602writedat(*0*+TIME[1]/16);
LCD1602writedat(*0*+(TIME[1]&0x0f));
LCD1602writedat(*-*);
LCD1602writedat(*0*+TIME[0]/16);
LCD1602writedat(*0*+(TIME[0]&0x0f));


LCD1602writecom(0x80);
LCD1602writedat(*2*);
LCD1602writedat(*0*);
LCD1602writedat(*1*+TIME[6]/16);
LCD1602writedat(*0*+(TIME[6]&0x0f));
LCD1602writedat(*-*);
LCD1602writedat(*0*+TIME[4]/16);
LCD1602writedat(*0*+(TIME[4]&0x0f));
LCD1602writedat(*-*);
LCD1602writedat(*0*+TIME[3]/16);
LCD1602writedat(*0*+(TIME[3]&0x0f));
LCD1602writecom(0x8D);
LCD1602writedat(*0*+(TIME[5]&0x07));
}
void main()
{
LCD1602init();
DS1302init();
while(1)
{
DS1302readtime();
LCDdisplay();
}
}



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
zheng296656
1楼-- · 2019-07-16 00:24
有事没事帮你顶~~~~~~~~~~~~~~~~~~~~
哎哟我去
2楼-- · 2019-07-16 02:47
 精彩回答 2  元偷偷看……
greenho
3楼-- · 2019-07-16 08:05
奋战到深夜,终于搞定了......

一周热门 更多>