;================================================
;DS1302控制子程序
;=================================================
;程序包括:DS1302初始化,時(shí)間數(shù)據(jù)寫入和讀取程序
;DS1302_init;initds1302
;Set_DS1302;settimetods1302
;Get_DS1302;gettimefromds1302
;=================================================
;==============1302定義===========================================
#DEFINET_IOPORTE,2;1302I_O
#DEFINET_CLKPORTE,1;1302時(shí)鐘
#DEFINET_RSTPORTE,0;1302使能位
#DEFINEDS1302_RX20H;保存接受的1個(gè)數(shù)據(jù)
#DEFINEDS1302_TX28H;準(zhǔn)備寫入到DS1302的一個(gè)數(shù)據(jù)
counterequxxxh
cntequxxxh
;**************************************************
;DS1302初始化程序
;**************************************************
DS1302_init
;未寫
return
;**********************************************************
;子程序名:Set_DS1302
;功能:設(shè)置DS1302初始時(shí)間,并啟動(dòng)計(jì)時(shí)。
;說明:
;調(diào)用:Write_byte
;入口參數(shù):初始時(shí)間在:W_Second,W_Minute,W_Hour,W_Day,W_Month,W_Week.W_YearL(地址連續(xù))
;出口參數(shù):無(wú)
;消耗資源:counter,SecAddr(預(yù)定義)
;設(shè)計(jì):zhengYanbo日期:2005.4.21
;修改:日期:
;**********************************************************
Set_DS1302:
bcfT_RST
bcfT_CLK
bsfT_RST
movlw8eh
movwfDS1302_TX;數(shù)據(jù)發(fā)送寄存器
callWrite_byte;發(fā)送字節(jié)
movlw00h;WP=0
movwfDS1302_TX
callWrite_byte
bsfT_CLK
bcfT_RST
movlwW_Second
movwfFSR
movlwcounter,D’7’
movlw80h
movwfSecAddr;秒寫地址
S13021:
bcfT_RST
bcfT_CLK
bsfT_RST
movfSecAddr,W
movwfDS1302_TX
callWrite_byte;寫秒地址
movfINDF,W
movwfDS1302_TX
callWrite_byte;寫秒數(shù)據(jù)
incfFSR
incfSecAddr
incfSecAddr
bsfT_CLK
bcfT_RST
decfszcounter,F
gotoS13021
bcfT_RST
bcfT_CLK
bsfT_RST
movlw8eh;控制寄存器
movwfDS1302_TX
callWrite_byte
movlw80h;控制WP=1,寫保護(hù)
movwfDS1302_TX
callWrite_byte
bsfT_CLK
bcfT_RST
return
;**********************************************************
;子程序名:Get_DS1302
;功能:從DS1302讀時(shí)間
;說明:
;調(diào)用:Write_byte,Read_byte
;入口參數(shù):時(shí)間保存在:R_Second,R_Minute,R_Hour,R_Day,R_Month,R_Week.R_YearL
;出口參數(shù):無(wú)
;消耗資源:counter,SecAddr(預(yù)先定義)
;設(shè)計(jì):zhengYanbo日期:2005.4.21
;修改:日期:
;**********************************************************
Get_DS1302:
movlwR_Second;準(zhǔn)備地址
movwfFSR
movlwD’7’
movwfcounter
movlw81h;秒讀地址
movwfSecAddr
G13021
bcfT_RST
bcfT_CLK
bsfT_RST
movfSecAddr,W
movwfDS1302_TX
callWrite_byte
callRead_byte
movfDS1302_RX,W
movwfINDF
incfFSR
incfSecAddr
incfSecAddr
bsfT_CLK
bcfT_RST
decfszcounter,F;接受7個(gè)數(shù)據(jù)
gotoG13021
return
;**********************************************************
;功能:寫1302一字節(jié)(內(nèi)部子程序)
;入口:數(shù)據(jù)預(yù)先在DS1302_TX中
;出口:無(wú)
;消耗資源:cnt(預(yù)先定義)
;**********************************************************
Write_byte
movlwD’8’
movwftmp_cnt
W_shift
rrfDS1302_TX,F;帶C移位(低位在前)
btfscSTATUS,C
gotosend_1
bcfT_IO
gotosend_0
send_1
bsfT_IO
send_0
bsfT_CLK;上升沿寫
nop
bcfT_CLK
decfszcnt,F
gotoW_shift
return
;**********************************************************
;功能:讀1302一字節(jié)(內(nèi)部子程序)
;入口:無(wú)
;出口:數(shù)據(jù)保存在DS1302_RX中
;消耗資源:cnt(預(yù)先定義)
;**********************************************************
Read_byte
bsfSTATUS,RP0;bank1
bsfTRISE,2;設(shè)置串行數(shù)據(jù)口為輸入
bcfSTATUS,RP0;bank0
movlwD’8’
movwfcnt
R_shift
btfscT_IO
gotoget_1
bcfSTATUS,C;clrc
gotoget_0
get_1
bsfSTATUS,C
get_0
rrfDS1302_RX,F
bsfT_CLK
nop
bcfT_CLK;下降沿讀
decfszcnt,F
gotoR_shift
;resetoutput
bsfSTATUS,RP0;bank1
bcfTRISE,2;設(shè)置T_IO為輸出
bcfSTATUS,RP0;bank0
return
這個(gè)程序一定要,PIC默認(rèn)PORTE為A/D口,切記,切記!改為其他口時(shí)候請(qǐng)參考PIC的DATASHEET
;=============================================
;初始化端口
;=============================================
Port_Init
bsfSTATUS,RP0;bank1
bcfADCON1,PCFG0
bsfADCON1,PCFG1
bsfADCON1,PCFG2
bcfADCON1,PCFG3;PORTAandPORTE:digitalI/O
bcfSTATUS,RP0;bank0
return