找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1799|回復(fù): 0
收起左側(cè)

藍(lán)橋杯-CT107單片機(jī)綜合實(shí)訓(xùn)平臺(tái)-數(shù)字鐘ds1302

[復(fù)制鏈接]
ID:142045 發(fā)表于 2019-3-21 09:06 | 顯示全部樓層 |閱讀模式
/*
  程序說(shuō)明: DS1302驅(qū)動(dòng)程序
  軟件環(huán)境: Keil uVision 4.10
  硬件環(huán)境: CT107單片機(jī)綜合實(shí)訓(xùn)平臺(tái) 8051,12MHz
  日    期: 2019-8-9
*/

#include <reg52.h>
#include <intrins.h>

sbit SCK=P1^7;               
sbit SDA=P2^3;               
sbit RST = P1^3;   // DS1302復(fù)位                                                                                               

void Write_Ds1302(unsigned  char temp)
{
        unsigned char i;
        for (i=0;i<8;i++)            
        {
                SCK=0;
                SDA=temp&0x01;
                temp>>=1;
                SCK=1;
        }
}   

void Write_Ds1302_Byte( unsigned char address,unsigned char dat )     
{
        RST=0;        _nop_();
        SCK=0;        _nop_();
        RST=1;         _nop_();  
        Write_Ds1302(address);       
        Write_Ds1302(dat);               
        RST=0;
}

unsigned char Read_Ds1302_Byte ( unsigned char address )
{
        unsigned char i,temp=0x00;
        RST=0;        _nop_();
        SCK=0;        _nop_();
        RST=1;        _nop_();
        Write_Ds1302(address);
        for (i=0;i<8;i++)        
        {               
                SCK=0;
                temp>>=1;       
                if(SDA)
                temp|=0x80;       
                SCK=1;
        }
        RST=0;        _nop_();
        SCK=0;        _nop_();
        SCK=1;        _nop_();
        SDA=0;        _nop_();
        SDA=1;        _nop_();
        return (temp);                       
}


ds1302.rar

755 Bytes, 下載次數(shù): 6, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表