標題: ds1302的31個ram讀寫 [打印本頁]

作者: 清楓城主    時間: 2018-4-20 14:50
標題: ds1302的31個ram讀寫
    目前正在做一個萬年歷鬧鐘,考慮到掉電保存,開發(fā)板上的單片機尷尬的是竟然沒有EEPROM,因此把主意打到DS1302來,后期更換單片機后會把鬧鐘數(shù)據(jù)保存到單片機而不是DS1302中,DS1302如果掉電(后背電池也沒電)情況下數(shù)據(jù)就丟失了。
    這31個RAM的讀寫跟時鐘寄存器的讀寫一樣,就是讀是奇數(shù),寫是偶數(shù),這個要注意,有的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ù)在上升沿時,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ù)在上升沿時,DS1302讀取數(shù)據(jù)
                _nop_();
                SCLK = 0;
                _nop_();       
        }       
        RST = 0;//傳送數(shù)據(jù)結(jié)束
        _nop_();
}

/*******************************************************************************
* 函 數(shù) 名         : Ds1302Read
* 函數(shù)功能                   : 讀取一個地址的數(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ù)在上升沿時,DS1302讀取數(shù)據(jù)
                _nop_();
                SCLK = 0;//DS1302下降沿時,放置數(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ù)據(jù)
                _nop_();
        }
        RST = 0;
        _nop_();        //以下為DS1302復(fù)位的穩(wěn)定時間,必須的。
        SCLK = 1;
        _nop_();
        DSIO = 0;
        _nop_();
        DSIO = 1;
        _nop_();
        return dat;       
}

/***************************************
* 函 數(shù) 名        : test
* 函數(shù)功能      : 先對特定地址進行讀數(shù)據(jù),對數(shù)據(jù)進行比對是否成功寫入。循環(huán)中是一個寫入測試。
* 輸    入         : 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;
                }
        }
}



作者: 謎鹿    時間: 2019-2-16 16:00
感謝樓主,百度找了半天DS1302將時間存入RAM都沒找到有用的,看到樓主這篇博文里面內(nèi)容“這31個RAM的讀寫跟時鐘寄存器的讀寫一樣,就是讀是奇數(shù),寫是偶數(shù),這個要注意,有的PPT講的容易搞混!蔽也琶靼孜夷谴a問題出在哪里,特別感謝
作者: 謎鹿    時間: 2019-2-16 16:18
感謝樓主幫助,剛修改了一下代碼,實現(xiàn)了我需要的功能。

需要實現(xiàn)的目標:在液晶上以二行的形式顯示出時鐘,按下k1  后將當前時間存入ds1302的RAM中,時鐘正常顯示。選擇一個按鍵k2,
按下 k2  后顯示按下 k1 的時間
,在選擇一個按鍵k3,按下k3  后 ,恢復(fù)顯示當前時間。
我使用的是普中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++)//讀取七個字節(jié)的時鐘信號:分秒時日月周年
                        {
                                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個值,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); //禁止寫保護
        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****/
/*****************************************************************************************/


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




作者: 謎鹿    時間: 2019-2-16 19:38
感謝樓主幫助,剛修改了一下代碼,實現(xiàn)了我需要的功能。

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

我使用的是普中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++)//讀取七個字節(jié)的時鐘信號:分秒時日月周年
                        {
                                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個值,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); //禁止寫保護
        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****/
/*****************************************************************************************/

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







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1