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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5901|回復: 3
打印 上一主題 下一主題
收起左側

ds1302的31個ram讀寫

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


/*******************************************************************************
* 函 數 名         : Ds1302Write
* 函數功能                   : 向DS1302命令(地址+數據)
* 輸    入         : 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;//數據從低位開始傳送
                addr >>= 1;
                SCLK = 1;//數據在上升沿時,DS1302讀取數據
                _nop_();
                SCLK = 0;
                _nop_();
        }
        for (n=8; n>0; n--)//寫入8位數據
        {
                DSIO = dat & 0x01;
                dat >>= 1;
                SCLK = 1;//數據在上升沿時,DS1302讀取數據
                _nop_();
                SCLK = 0;
                _nop_();       
        }       
        RST = 0;//傳送數據結束
        _nop_();
}

/*******************************************************************************
* 函 數 名         : Ds1302Read
* 函數功能                   : 讀取一個地址的數據
* 輸    入         : 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;//數據從低位開始傳送
                addr >>= 1;
                SCLK = 1;//數據在上升沿時,DS1302讀取數據
                _nop_();
                SCLK = 0;//DS1302下降沿時,放置數據
                _nop_();
        }
        _nop_();
        for(n=0; n<8; n++)//讀取8位數據
        {
                dat1 = DSIO;//從最低位開始接收
                dat = (dat>>1) | (dat1<<7);
                SCLK = 1;
                _nop_();
                SCLK = 0;//DS1302下降沿時,放置數據
                _nop_();
        }
        RST = 0;
        _nop_();        //以下為DS1302復位的穩定時間,必須的。
        SCLK = 1;
        _nop_();
        DSIO = 0;
        _nop_();
        DSIO = 1;
        _nop_();
        return dat;       
}

/***************************************
* 函 數 名        : test
* 函數功能      : 先對特定地址進行讀數據,對數據進行比對是否成功寫入。循環中是一個寫入測試。
* 輸    入         : addr
* 輸    出         : dat
***************************************/

void test()
{
        LCD_CLS();//OLDE清屏
        LCD_english_chinese(1,32,0,"鬧鐘設置");//在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;
                }
        }
}


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

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

使用道具 舉報

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

需要實現的目標:在液晶上以二行的形式顯示出時鐘,按下k1  后將當前時間存入ds1302的RAM中,時鐘正常顯示。選擇一個按鍵k2,
按下 k2  后顯示按下 k1 的時間
,在選擇一個按鍵k3,按下k3  后 ,恢復顯示當前時間。
我使用的是普中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++)//讀取七個字節的時鐘信號:分秒時日月周年
                        {
                                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讀入數據只有2個值,0x01和0x00,只看0x01那么<<7后變成0x80,
                //再看dat假如dat=0x80,>>1后變成0x40, 0x40. /0x80=1100 0000B.
                //簡單說就是一位一位讀入串行數據。
                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); //禁止寫保護
        for(n=0;n<7;n++)
        {
                DS1302write(RTCwriteaddr[n],TIME[n]);       
        }
        DS1302write(0x8E,0x80); //開啟寫保護
}

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****/
/*****************************************************************************************/


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



回復

使用道具 舉報

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

需要實現的目標:在液晶上以二行的形式顯示出時鐘,按下k1  后將當前時間存入ds1302的RAM中,時鐘正常顯示。選擇一個按鍵k2,
按下 k2  后顯示按下 k1 的時間,在選擇一個按鍵k3,按下k3  后 ,恢復顯示當前時間。

我使用的是普中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++)//讀取七個字節的時鐘信號:分秒時日月周年
                        {
                                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讀入數據只有2個值,0x01和0x00,只看0x01那么<<7后變成0x80,
                //再看dat假如dat=0x80,>>1后變成0x40, 0x40. /0x80=1100 0000B.
                //簡單說就是一位一位讀入串行數據。
                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); //禁止寫保護
        for(n=0;n<7;n++)
        {
                DS1302write(RTCwriteaddr[n],TIME[n]);       
        }
        DS1302write(0x8E,0x80); //開啟寫保護
}

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****/
/*****************************************************************************************/

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


回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 蜜月aⅴ免费一区二区三区 99re在线视频 | 亚洲免费在线观看 | 亚洲精品在线播放 | 午夜一区二区三区在线观看 | 伊人国产精品 | 国产欧美一区二区三区在线看 | 久久九九免费 | 国产一级片免费在线观看 | 国产激情一区二区三区 | 97碰碰碰| 欧美成人一区二区三区 | 久久国产精品无码网站 | 久久国产电影 | 91久久国产综合久久 | 欧美日韩亚洲一区 | 婷婷激情五月网 | 丝袜美腿一区 | 国产在线网站 | 欧美一级片在线观看 | 欧美日本亚洲 | 精品视频在线播放 | 97视频在线免费 | 日韩免费中文字幕 | 欧美国产日韩精品 | www久久国产 | 午夜网| 天天色官网 | 久久国产精品视频 | 成人欧美一区二区三区黑人孕妇 | 黄色一级大片在线免费看产 | 午夜视频在线播放 | 成人小视频在线观看 | 久久久久综合 | 波多野结衣先锋影音 | 欧美一区不卡 | 黄色毛片一级 | 瑟瑟激情 | 国产精品成人一区二区 | 国产精品高潮呻吟久久久久 | 奇色影视 | 日韩在线一区二区三区 |