程序问题,求教了T_T
时间:10-02
整理:3721RD
点击:
显示的不是设定的初始值,反而一直显示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();
}
}
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();
}
}
有事没事帮你顶~~~~~~~~~~~~~~~~~~~~
你这么贴一大堆程序是很难叫人帮你完全看完的。 你倒不如贴关键的程序段就行 。 自己要理解那些程序才能写出效果
奋战到深夜,终于搞定了......