久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5844|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

ds1302的31個(gè)ram讀寫

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:310680 發(fā)表于 2018-4-20 14:50 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
    目前正在做一個(gè)萬年歷鬧鐘,考慮到掉電保存,開發(fā)板上的單片機(jī)尷尬的是竟然沒有EEPROM,因此把主意打到DS1302來,后期更換單片機(jī)后會(huì)把鬧鐘數(shù)據(jù)保存到單片機(jī)而不是DS1302中,DS1302如果掉電(后背電池也沒電)情況下數(shù)據(jù)就丟失了。
    這31個(gè)RAM的讀寫跟時(shí)鐘寄存器的讀寫一樣,就是讀是奇數(shù),寫是偶數(shù),這個(gè)要注意,有的PPT講的容易搞混。


/*******************************************************************************
* 函 數(shù) 名         : Ds1302Write
* 函數(shù)功能                   : 向DS1302命令(地址+數(shù)據(jù))
* 輸    入         : addr,dat
* 輸    出         : 無
*******************************************************************************/

void Ds1302Write(uchar addr, uchar dat)
{
        uchar n;
        RST = 0;
        _nop_();
        SCLK = 0;//先將SCLK置低電平。
        _nop_();
        RST = 1; //然后將RST(CE)置高電平。
        _nop_();
        for (n=8; n>0; n--)//開始傳送八位地址命令
        {
                DSIO = addr & 0x01;//數(shù)據(jù)從低位開始傳送
                addr >>= 1;
                SCLK = 1;//數(shù)據(jù)在上升沿時(shí),DS1302讀取數(shù)據(jù)
                _nop_();
                SCLK = 0;
                _nop_();
        }
        for (n=8; n>0; n--)//寫入8位數(shù)據(jù)
        {
                DSIO = dat & 0x01;
                dat >>= 1;
                SCLK = 1;//數(shù)據(jù)在上升沿時(shí),DS1302讀取數(shù)據(jù)
                _nop_();
                SCLK = 0;
                _nop_();       
        }       
        RST = 0;//傳送數(shù)據(jù)結(jié)束
        _nop_();
}

/*******************************************************************************
* 函 數(shù) 名         : Ds1302Read
* 函數(shù)功能                   : 讀取一個(gè)地址的數(shù)據(jù)
* 輸    入         : addr
* 輸    出         : dat
*******************************************************************************/
uchar Ds1302Read(uchar addr)
{
        uchar n,dat,dat1;
        RST = 0;
        _nop_();
        SCLK = 0;//先將SCLK置低電平。
        _nop_();
        RST = 1;//然后將RST(CE)置高電平。
        _nop_();
        for(n=0; n<8; n++)//開始傳送八位地址命令
        {
                DSIO = addr & 0x01;//數(shù)據(jù)從低位開始傳送
                addr >>= 1;
                SCLK = 1;//數(shù)據(jù)在上升沿時(shí),DS1302讀取數(shù)據(jù)
                _nop_();
                SCLK = 0;//DS1302下降沿時(shí),放置數(shù)據(jù)
                _nop_();
        }
        _nop_();
        for(n=0; n<8; n++)//讀取8位數(shù)據(jù)
        {
                dat1 = DSIO;//從最低位開始接收
                dat = (dat>>1) | (dat1<<7);
                SCLK = 1;
                _nop_();
                SCLK = 0;//DS1302下降沿時(shí),放置數(shù)據(jù)
                _nop_();
        }
        RST = 0;
        _nop_();        //以下為DS1302復(fù)位的穩(wěn)定時(shí)間,必須的。
        SCLK = 1;
        _nop_();
        DSIO = 0;
        _nop_();
        DSIO = 1;
        _nop_();
        return dat;       
}

/***************************************
* 函 數(shù) 名        : test
* 函數(shù)功能      : 先對特定地址進(jìn)行讀數(shù)據(jù),對數(shù)據(jù)進(jìn)行比對是否成功寫入。循環(huán)中是一個(gè)寫入測試。
* 輸    入         : addr
* 輸    出         : dat
***************************************/

void test()
{
        LCD_CLS();//OLDE清屏
        LCD_english_chinese(1,32,0,"鬧鐘設(shè)置");//在OLED12864顯示屏上顯示提示
        if(Ds1302Read(0xc1)==0x55)//讀出
                P1=0x00;
        for(;;)
        {
                if(KEY1 == 0)//寫入
                {
                        Delay_M(10);
                          while(KEY1 == 0);
                        Ds1302Write(0x8E,0X00);
                        Ds1302Write(0xc0,0x55);
                        Ds1302Write(0x8E,0X80);
                }
                if(KEY4 == 0)//退出
                {
                        Delay_M(10);
                        while(KEY4 == 0);
                        return;
                }
        }
}


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:421451 發(fā)表于 2019-2-16 16:00 | 只看該作者
感謝樓主,百度找了半天DS1302將時(shí)間存入RAM都沒找到有用的,看到樓主這篇博文里面內(nèi)容“這31個(gè)RAM的讀寫跟時(shí)鐘寄存器的讀寫一樣,就是讀是奇數(shù),寫是偶數(shù),這個(gè)要注意,有的PPT講的容易搞混。”我才明白我那代碼問題出在哪里,特別感謝
回復(fù)

使用道具 舉報(bào)

板凳
ID:421451 發(fā)表于 2019-2-16 16:18 | 只看該作者
感謝樓主幫助,剛修改了一下代碼,實(shí)現(xiàn)了我需要的功能。

需要實(shí)現(xiàn)的目標(biāo):在液晶上以二行的形式顯示出時(shí)鐘,按下k1  后將當(dāng)前時(shí)間存入ds1302的RAM中,時(shí)鐘正常顯示。選擇一個(gè)按鍵k2,
按下 k2  后顯示按下 k1 的時(shí)間
,在選擇一個(gè)按鍵k3,按下k3  后 ,恢復(fù)顯示當(dāng)前時(shí)間。
我使用的是普中STC89C52的板子。

直接附代碼,希望能幫到和我遇到同樣問題的人。沒寫注釋,抱歉~~~~


/*****************************************************************************************/
/****************************************main.c********************************************/
/*****************************************************************************************/

#include "reg52.h"
#include "DS1302.h"
#include "LCD1602.h"

sbit K1 = P3^1;
sbit K2 = P3^0;
sbit K3 = P3^2;

uchar TIMEtemp1[7];
uchar TIMEtemp2[7];
uchar code RAMreadaddr[7] = {0xc1,0xc3,0xc5,0xc7,0xc9,0xcb,0xcd};
uchar code RAMwriteaddr[7] = {0xc0,0xc2,0xc4,0xc6,0xc8,0xca,0xcc};

void LCD1602display();
void delay10ms(void);
void keypress();

void main()
{
        LCD1602Init();
        DS1302Init();
        while(1)
        {
                DS1302readtime();
                LCD1602display();
                keypress();
        }
}

void LCD1602display()
{
        LCDwriteorder(0x80);
        LCDwritedata('2');
        LCDwritedata('0');
        LCDwritedata('0'+TIME[6]/16);    //year
        LCDwritedata('0'+(TIME[6]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[4]/16);         //month
        LCDwritedata('0'+(TIME[4]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[3]/16);         //day
        LCDwritedata('0'+(TIME[3]&0x0f));
        LCDwriteorder(0x8D);
        LCDwritedata('0'+(TIME[5]&0x07));//week

    LCDwriteorder(0x80+0x40);
        LCDwritedata('0'+TIME[2]/16);    //hour
        LCDwritedata('0'+(TIME[2]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[1]/16);         //minute
        LCDwritedata('0'+(TIME[1]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[0]/16);         //second
        LCDwritedata('0'+(TIME[0]&0x0f));
}

void delay10ms(void)   //10  ms 0  mission
{
    unsigned char a,b,c;
    for(c=1;c>0;c--)
        for(b=38;b>0;b--)
            for(a=130;a>0;a--);
}

void keypress()
{
        uchar n;
        if(K1==0)
        {
                delay10ms();
                if(K1==0)
                {
                        for (n=0; n<7; n++)//讀取七個(gè)字節(jié)的時(shí)鐘信號:分秒時(shí)日月周年
                        {
                                TIMEtemp1[n] = DS1302read(RTCreadaddr[n]);
                        }
                        DS1302write(0x8E,0x00);
                        for(n=0;n<7;n++)
                        {
                                DS1302write(RAMwriteaddr[n],TIMEtemp1[n]);
                        }
                        DS1302write(0x8E,0x80);               
                }
                while(!K1);       
        }

        if(K2==0)
        {
                delay10ms();
                if(K2==0)
                {
                        for(n=0;n<7;n++)
                        {
                                TIMEtemp2[n]=DS1302read(RAMreadaddr[n]);
                        }


                        while(1)
                        {
                                LCDwriteorder(0x80);
                                LCDwritedata('2');
                                LCDwritedata('0');
                                LCDwritedata('0'+TIMEtemp2[6]/16);    //year
                                LCDwritedata('0'+(TIMEtemp2[6]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[4]/16);         //month
                                LCDwritedata('0'+(TIMEtemp2[4]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[3]/16);         //day
                                LCDwritedata('0'+(TIMEtemp2[3]&0x0f));
                                LCDwriteorder(0x8D);
                                LCDwritedata('0'+(TIMEtemp2[5]&0x07));//week

                                  LCDwriteorder(0x80+0x40);
                                LCDwritedata('0'+TIMEtemp2[2]/16);    //hour
                                LCDwritedata('0'+(TIMEtemp2[2]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[1]/16);         //minute
                                LCDwritedata('0'+(TIMEtemp2[1]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[0]/16);         //second
                                LCDwritedata('0'+(TIMEtemp2[0]&0x0f));


                                if(K3==0)
                                {
                                        delay10ms();
                                        if(K3==0)
                                        {
                                                LCD1602display();
                                                break;
                                        }
                                }         
                        }
                }               
        }
}


/*****************************************************************************************/
/****************************************DS1302.h*****************************************/
/*****************************************************************************************/



#define __DS1302_H_

#include "reg52.h"
#include "intrins.h"

#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

sbit DSIO = P3^4;
sbit RST = P3^5;
sbit SCLK = P3^6;

void DS1302write(uchar addr,uchar dat);
uchar DS1302read(uchar addr);
void DS1302Init();
void DS1302readtime();

extern uchar TIME[7];
extern uchar code RTCreadaddr[7];
extern uchar code RTCwriteaddr[7];

#endif


/*****************************************************************************************/
/****************************************DS1302.c*****************************************/
/*****************************************************************************************/

#include "DS1302.h"

uchar code RTCreadaddr[7] = {0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar code RTCwriteaddr[7] = {0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};

uchar TIME[7]={0,0,0,0x14,0x02,0x04,0x19};// 00:00:00   14-2-19

void DS1302write(uchar addr,uchar dat)
{
        uchar n;
        RST = 0;    //CE
        _nop_();

        SCLK = 0 ;
        _nop_();
        RST = 1;
        _nop_();

        for(n=0;n<8;n++)            //address
        {
                DSIO = addr & 0x01;                  //低位開始傳送
                addr >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        for(n=0;n<8;n++)                  //order
        {
                DSIO = dat & 0x01;
                dat >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        RST = 0;
        _nop_();
}

uchar DS1302read(uchar addr)
{
        uchar n,dat,dat1;
        RST = 0;
        _nop_();

        SCLK = 0;
        _nop_();
        RST = 1;
        _nop_();

        for(n=0;n<8;n++)
        {
                DSIO = addr & 0x01;
                addr >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        _nop_();

        for(n=0;n<8;n++)
        {
                dat1 = DSIO;
                dat = (dat>>1)|(dat1<<7);
                //data1讀入數(shù)據(jù)只有2個(gè)值,0x01和0x00,只看0x01那么<<7后變成0x80,
                //再看dat假如dat=0x80,>>1后變成0x40, 0x40. /0x80=1100 0000B.
                //簡單說就是一位一位讀入串行數(shù)據(jù)。
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        RST = 0;
        _nop_();

        SCLK = 1;
        _nop_();
        DSIO = 0;
        _nop_();
        DSIO = 1;
        _nop_();

        return dat;
}

void DS1302Init()
{
        uchar n;
        DS1302write(0x8E,0x00); //禁止寫保護(hù)
        for(n=0;n<7;n++)
        {
                DS1302write(RTCwriteaddr[n],TIME[n]);       
        }
        DS1302write(0x8E,0x80); //開啟寫保護(hù)
}

void DS1302readtime()
{
        uchar n;
        for(n=0;n<7;n++)
        {
                TIME[n] = DS1302read(RTCreadaddr[n]);
        }
}



/*****************************************************************************************/
/****************************************LCD1602.h*****************************************/
/*****************************************************************************************/

#ifndef __LCD_H_
#define __LCD_H_

#include "reg52.h"

#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

#define LCD1602_DATAPINS P0
sbit LCD1602_E = P2^7;
sbit LCD1602_RW = P2^5;
sbit LCD1602_RS = P2^6;

void LCD1602_delay1ms(uint c);
void LCDwriteorder(uchar order);
void LCDwritedata(uchar dat);
void LCD1602Init();

#endif


/*****************************************************************************************/
/****************************************LCD1602.c*****************************************/
/*****************************************************************************************/


#include "LCD1602.h"

void LCD1602_delay1ms(uint c)   //1ms , 0 mission       
{
    uchar a,b;
        for (; c>0; c--)
        {
                 for (b=199;b>0;b--)
                 {
                          for(a=1;a>0;a--);
                 }      
        }         
}

void LCDwriteorder(uchar order)
{
        LCD1602_E = 0;                //power  open
        LCD1602_RS = 0;                //send order
        LCD1602_RW = 0;            //choose write

        LCD1602_DATAPINS = order;
        LCD1602_delay1ms(1);   

        LCD1602_E = 1;
        LCD1602_delay1ms(5);
        LCD1602_E = 0;
}

void LCDwritedata(uchar dat)
{
        LCD1602_E = 0;
        LCD1602_RS = 1; //send data
        LCD1602_RW = 0;

        LCD1602_DATAPINS = dat;
        LCD1602_delay1ms(1);

        LCD1602_E = 1;
        LCD1602_delay1ms(5);
        LCD1602_E = 0;
}

void LCD1602Init()
{
        LCDwriteorder(0x38); //display open
        LCDwriteorder(0x0c); // no flash sign
        LCDwriteorder(0x06); // one date one point
        LCDwriteorder(0x01); // rush screen
        LCDwriteorder(0x80); //        set point start space
}


/*****************************************************************************************/
/****end********end*********end******end*****end****end*****end********end**********end****/
/*****************************************************************************************/


再次感謝樓主,哈哈哈哈哈哈哈哈~~~~~~~



回復(fù)

使用道具 舉報(bào)

地板
ID:421451 發(fā)表于 2019-2-16 19:38 | 只看該作者
感謝樓主幫助,剛修改了一下代碼,實(shí)現(xiàn)了我需要的功能。

需要實(shí)現(xiàn)的目標(biāo):在液晶上以二行的形式顯示出時(shí)鐘,按下k1  后將當(dāng)前時(shí)間存入ds1302的RAM中,時(shí)鐘正常顯示。選擇一個(gè)按鍵k2,
按下 k2  后顯示按下 k1 的時(shí)間,在選擇一個(gè)按鍵k3,按下k3  后 ,恢復(fù)顯示當(dāng)前時(shí)間。

我使用的是普中STC89C52的板子。

直接附代碼,希望能幫到和我遇到同樣問題的人。沒寫注釋,抱歉~~~~


/*****************************************************************************************/
/****************************************main.c********************************************/
/*****************************************************************************************/

#include "reg52.h"
#include "DS1302.h"
#include "LCD1602.h"

sbit K1 = P3^1;
sbit K2 = P3^0;
sbit K3 = P3^2;

uchar TIMEtemp1[7];
uchar TIMEtemp2[7];
uchar code RAMreadaddr[7] = {0xc1,0xc3,0xc5,0xc7,0xc9,0xcb,0xcd};
uchar code RAMwriteaddr[7] = {0xc0,0xc2,0xc4,0xc6,0xc8,0xca,0xcc};

void LCD1602display();
void delay10ms(void);
void keypress();

void main()
{
        LCD1602Init();
        DS1302Init();
        while(1)
        {
                DS1302readtime();
                LCD1602display();
                keypress();
        }
}

void LCD1602display()
{
        LCDwriteorder(0x80);
        LCDwritedata('2');
        LCDwritedata('0');
        LCDwritedata('0'+TIME[6]/16);    //year
        LCDwritedata('0'+(TIME[6]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[4]/16);         //month
        LCDwritedata('0'+(TIME[4]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[3]/16);         //day
        LCDwritedata('0'+(TIME[3]&0x0f));
        LCDwriteorder(0x8D);
        LCDwritedata('0'+(TIME[5]&0x07));//week

    LCDwriteorder(0x80+0x40);
        LCDwritedata('0'+TIME[2]/16);    //hour
        LCDwritedata('0'+(TIME[2]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[1]/16);         //minute
        LCDwritedata('0'+(TIME[1]&0x0f));
        LCDwritedata('-');
        LCDwritedata('0'+TIME[0]/16);         //second
        LCDwritedata('0'+(TIME[0]&0x0f));
}

void delay10ms(void)   //10  ms 0  mission
{
    unsigned char a,b,c;
    for(c=1;c>0;c--)
        for(b=38;b>0;b--)
            for(a=130;a>0;a--);
}

void keypress()
{
        uchar n;
        if(K1==0)
        {
                delay10ms();
                if(K1==0)
                {
                        for (n=0; n<7; n++)//讀取七個(gè)字節(jié)的時(shí)鐘信號:分秒時(shí)日月周年
                        {
                                TIMEtemp1[n] = DS1302read(RTCreadaddr[n]);
                        }
                        DS1302write(0x8E,0x00);
                        for(n=0;n<7;n++)
                        {
                                DS1302write(RAMwriteaddr[n],TIMEtemp1[n]);
                        }
                        DS1302write(0x8E,0x80);               
                }
                while(!K1);       
        }

        if(K2==0)
        {
                delay10ms();
                if(K2==0)
                {
                        for(n=0;n<7;n++)
                        {
                                TIMEtemp2[n]=DS1302read(RAMreadaddr[n]);
                        }


                        while(1)
                        {
                                LCDwriteorder(0x80);
                                LCDwritedata('2');
                                LCDwritedata('0');
                                LCDwritedata('0'+TIMEtemp2[6]/16);    //year
                                LCDwritedata('0'+(TIMEtemp2[6]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[4]/16);         //month
                                LCDwritedata('0'+(TIMEtemp2[4]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[3]/16);         //day
                                LCDwritedata('0'+(TIMEtemp2[3]&0x0f));
                                LCDwriteorder(0x8D);
                                LCDwritedata('0'+(TIMEtemp2[5]&0x07));//week

                                  LCDwriteorder(0x80+0x40);
                                LCDwritedata('0'+TIMEtemp2[2]/16);    //hour
                                LCDwritedata('0'+(TIMEtemp2[2]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[1]/16);         //minute
                                LCDwritedata('0'+(TIMEtemp2[1]&0x0f));
                                LCDwritedata('-');
                                LCDwritedata('0'+TIMEtemp2[0]/16);         //second
                                LCDwritedata('0'+(TIMEtemp2[0]&0x0f));


                                if(K3==0)
                                {
                                        delay10ms();
                                        if(K3==0)
                                        {
                                                LCD1602display();
                                                break;
                                        }
                                }         
                        }
                }               
        }
}

/*****************************************************************************************/
/****************************************DS1302.h*****************************************/
/*****************************************************************************************/


#define __DS1302_H_

#include "reg52.h"
#include "intrins.h"

#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

sbit DSIO = P3^4;
sbit RST = P3^5;
sbit SCLK = P3^6;

void DS1302write(uchar addr,uchar dat);
uchar DS1302read(uchar addr);
void DS1302Init();
void DS1302readtime();

extern uchar TIME[7];
extern uchar code RTCreadaddr[7];
extern uchar code RTCwriteaddr[7];

#endif

/*****************************************************************************************/
/****************************************DS1302.c*****************************************/
/*****************************************************************************************/
#include "DS1302.h"

uchar code RTCreadaddr[7] = {0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar code RTCwriteaddr[7] = {0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};

uchar TIME[7]={0,0,0,0x14,0x02,0x04,0x19};// 00:00:00   14-2-19

void DS1302write(uchar addr,uchar dat)
{
        uchar n;
        RST = 0;    //CE
        _nop_();

        SCLK = 0 ;
        _nop_();
        RST = 1;
        _nop_();

        for(n=0;n<8;n++)            //address
        {
                DSIO = addr & 0x01;                  //低位開始傳送
                addr >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        for(n=0;n<8;n++)                  //order
        {
                DSIO = dat & 0x01;
                dat >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        RST = 0;
        _nop_();
}

uchar DS1302read(uchar addr)
{
        uchar n,dat,dat1;
        RST = 0;
        _nop_();

        SCLK = 0;
        _nop_();
        RST = 1;
        _nop_();

        for(n=0;n<8;n++)
        {
                DSIO = addr & 0x01;
                addr >>= 1;
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        _nop_();

        for(n=0;n<8;n++)
        {
                dat1 = DSIO;
                dat = (dat>>1)|(dat1<<7);
                //data1讀入數(shù)據(jù)只有2個(gè)值,0x01和0x00,只看0x01那么<<7后變成0x80,
                //再看dat假如dat=0x80,>>1后變成0x40, 0x40. /0x80=1100 0000B.
                //簡單說就是一位一位讀入串行數(shù)據(jù)。
                SCLK = 1;
                _nop_();
                SCLK = 0;
                _nop_();
        }

        RST = 0;
        _nop_();

        SCLK = 1;
        _nop_();
        DSIO = 0;
        _nop_();
        DSIO = 1;
        _nop_();

        return dat;
}

void DS1302Init()
{
        uchar n;
        DS1302write(0x8E,0x00); //禁止寫保護(hù)
        for(n=0;n<7;n++)
        {
                DS1302write(RTCwriteaddr[n],TIME[n]);       
        }
        DS1302write(0x8E,0x80); //開啟寫保護(hù)
}

void DS1302readtime()
{
        uchar n;
        for(n=0;n<7;n++)
        {
                TIME[n] = DS1302read(RTCreadaddr[n]);
        }
}


/*****************************************************************************************/
/****************************************LCD1602.h*****************************************/
/*****************************************************************************************/
#ifndef __LCD_H_
#define __LCD_H_

#include "reg52.h"

#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

#define LCD1602_DATAPINS P0
sbit LCD1602_E = P2^7;
sbit LCD1602_RW = P2^5;
sbit LCD1602_RS = P2^6;

void LCD1602_delay1ms(uint c);
void LCDwriteorder(uchar order);
void LCDwritedata(uchar dat);
void LCD1602Init();

#endif

/*****************************************************************************************/
/****************************************LCD1602.c*****************************************/
/*****************************************************************************************/

#include "LCD1602.h"

void LCD1602_delay1ms(uint c)   //1ms , 0 mission       
{
    uchar a,b;
        for (; c>0; c--)
        {
                 for (b=199;b>0;b--)
                 {
                          for(a=1;a>0;a--);
                 }      
        }         
}

void LCDwriteorder(uchar order)
{
        LCD1602_E = 0;                //power  open
        LCD1602_RS = 0;                //send order
        LCD1602_RW = 0;            //choose write

        LCD1602_DATAPINS = order;
        LCD1602_delay1ms(1);   

        LCD1602_E = 1;
        LCD1602_delay1ms(5);
        LCD1602_E = 0;
}

void LCDwritedata(uchar dat)
{
        LCD1602_E = 0;
        LCD1602_RS = 1; //send data
        LCD1602_RW = 0;

        LCD1602_DATAPINS = dat;
        LCD1602_delay1ms(1);

        LCD1602_E = 1;
        LCD1602_delay1ms(5);
        LCD1602_E = 0;
}

void LCD1602Init()
{
        LCDwriteorder(0x38); //display open
        LCDwriteorder(0x0c); // no flash sign
        LCDwriteorder(0x06); // one date one point
        LCDwriteorder(0x01); // rush screen
        LCDwriteorder(0x80); //        set point start space
}

/*****************************************************************************************/
/****end********end*********end******end*****end****end*****end********end**********end****/
/*****************************************************************************************/

再次感謝樓主,哈哈哈哈哈哈哈哈~~~~~~~


回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 欧美在线一级 | 国产精品亚洲片在线播放 | 神马影院一区二区三区 | 五月天国产 | 麻豆91精品91久久久 | 日韩中文字幕 | 国产高清在线视频 | 国产成人免费 | 国产视频一区二区 | 国产剧情久久 | 日本免费视频 | 99pao成人国产永久免费视频 | 中文字幕一区二区三区乱码在线 | 99re热精品视频 | 国产1页| 日本一区精品 | 99精品网| 国产黄色一级片 | 亚洲aⅴ | 日本精品裸体写真集在线观看 | 国产麻豆乱码精品一区二区三区 | 国产综合久久 | 91亚洲一区 | 欧美日韩在线观看一区 | 蜜桃视频在线观看免费视频网站www | 国产精品久久久久久久久久免费看 | 国产精品日韩欧美一区二区三区 | 一区二区三区免费 | 亚洲一区 中文字幕 | 久久伦理中文字幕 | www.玖玖玖| 成人av播放 | 9191av | 91精品国产一区二区三区 | 欧美综合自拍 | 毛片com | 日韩av手机在线观看 | 成年人网站国产 | 久久久激情视频 | 国产精品美女久久久久aⅴ国产馆 | 亚洲精品黑人 |