DS1302时钟程序问题,为什么最后显示出来的全是0,时间不会变化

2019-03-24 17:52发布

#include<reg51.h>

#include<intrins.h>
#define uchar unsigned char
#define uint  unsigned int

//--LCD--//
sbit LCD_RS=P2^6;//êy¾Y/ÃüáîÑ¡Ôñ¶Ë£¨H/L£©
sbit LCD_RW=P2^5;//¶á/D′ÃüáîÑ¡Ôñ¶Ë£¨H/L£©
sbit LCD_EN=P2^7;//ê1ÄüDÅoÅ
void LCD_write_com(uchar _com);//D′Ãüáî
void LCD_write_data(uchar _data);//D′êy¾Y
void LCD_init();//LCD3õê¼»ˉ
void delay1ms(uint c);

//--DS1302--//
sbit DS_SCLK=P3^6;
sbit DS_IO=P3^4;
sbit DS_RST=P3^5;
sbit DS_ACC0=ACC^0;
sbit DS_ACC7=ACC^7;
void DS_Write_Byte(uchar TD);//μ¥×Ö½úD′èë
uchar DS_Read_Byte();//μ¥×Ö½ú¶áè¡
void DS_Write_DS1302(uchar add,_data);//Ïò¼Ä′æÆ÷D′êy¾Y
uchar DS_Read_DS1302(uchar add);//′ó¼Ä′æÆ÷¶áêy¾Y
void DS1302_init();//DS13023õê¼»ˉ
void Display(uchar LCD_add,_data);

void delay1ms(uint c)//1msÑóê±
{
    unsigned char a,b;
    for(c;c>0;c--)
        for(b=142;b>0;b--)
            for(a=2;a>0;a--);
}

void LCD_write_com(uchar _com)//D′Ãüáî
{
LCD_RS=0;
LCD_RW=0;
P0=_com;
delay1ms(1);
LCD_EN=1;
delay1ms(1);
LCD_EN=0;
}

void LCD_write_data(uchar _data)//D′êy¾Y
{
LCD_RS=1;
LCD_RW=0;
P0=_data;
delay1ms(1);
LCD_EN=1;
delay1ms(1);
LCD_EN=0;
}

void LCD_init()//3õê¼»ˉ
{
LCD_EN=0;
LCD_write_com(0x38);//éèÖÃ16*2ÏÔê¾£¬5*7μãÕó£¬8λêy¾Y½ó¿ú
LCD_write_com(0x0F);//¿aÏÔ꾡¢ÏÔê¾1a±ê¡¢1a±êéá˸
LCD_write_com(0x06);//챶á»òD′ò»¸ö×Ö·ûoóμØÖ·Ö¸Õë¼óò»£¬Çò1a±ê¼óò»
LCD_write_com(0x01);//ËùóDÏÔê¾Çåáã
LCD_write_com(0x80);//éèÖÃêy¾YÖ¸ÕëλÖÃ
}

void Display(uchar LCD_add,_data)
{
uchar decade,the_unit;
decade=_data>>4;
the_unit=_data&0x0f;
LCD_write_com(LCD_add);
LCD_write_data(0x30+decade);
LCD_write_data(0x30+the_unit);
}






这是程序显示出来的样子


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。