Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
Dim Temp As Byte
Dim Temp1 As Byte
Dim TimeData[6] As Byte
Dim OldSeconds As Byte
Dim Seconds As timedata#0
Dim Minutes As timedata#1
Dim Hours As timedata#2
Dim Date As timedata#3
Dim Month As timedata#4
Dim Year As timedata#5
'Define registers
Symbol SECREG = %00000
Symbol MINREG = %00001
Symbol HRSREG = %00010
Symbol DATEREG = %00011
Symbol MONREG = %00100
Symbol YRREG = %00110
Symbol CTRLREG = %00111
Symbol BRSTREG = %11111
Symbol CLK = PORTC.3
Symbol DTA = PORTC.4
Symbol RST = PORTC.2
' Time setup data held in eeprom memory
PRST EData $59,$59,$23,$31,$03,$10,$10
All_Digital = True
Print At 1,1,"asdasd"
DelayMS 2000
Cls
' Clear Write Protect bit in control register of DS1302
Temp = $10
RTCcmd = CTRLREG
GoSub DS1302_WRITE
' Pre-set the time registers using a data table stored in eeprom memory
For Temp1 = 0 To 6
Temp = ERead PRST + Temp1
RTCcmd = Temp1
GoSub DS1302_WRITE
Next
Temp = $80
RTCcmd = CTRLREG
GoSub DS1302_READ
'Only Displays on the LCD if the seconds have changed
While 1 = 1
GoSub DS1302_READ
If OldSeconds <> Seconds Then
Print At 1,1, "TIME ", Hex2 Hours,":",Hex2 Minutes,":",Hex2 Seconds
Print At 2,1, "DATE ", Hex2 Date,"/",Hex2 Month,"/",Hex2 Year
EndIf
Wend
'-----------------------------------------------------------------------------------
' Write to DS1302 RTC
DS1302_WRITE:
High RST
SHOut DTA, CLK, LsbFirst, [%0\1,RTCcmd\5,%10\2,Temp\8]
Low RST
Return
'-----------------------------------------------------------------------------------
' Read from the DS1302
DS1302_READ:
High RST
SHOut DTA, CLK, LsbFirst, [%111111\6,%10\2]
OldSeconds = Seconds
SHIn DTA, CLK, LsbPre, [Seconds,Minutes,Hours,Date,Month,Year,Year]
Low RST
Return
*************************************************************
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.