Continue to Site

Welcome to EDAboard.com

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.

DS1307 with Pic16f690

Status
Not open for further replies.

JoeyW

Newbie level 2
Joined
Feb 17, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,290
I want to build a simple RTC using DS1307 and Pic16f690 can anyone help me with the code.

It has to be in picbasic

Thanks
 

here is the code

*************************************************************
Device = 18F452
Xtal = 20

LCD_DTPin = PORTD.4
LCD_RSPin = PORTE.0
LCD_ENPin = PORTE.1
LCD_Interface = 4 ' 4-bit Interface
LCD_Lines = 4
LCD_Type = 0
LCD_CommandUs = 2000
LCD_DataUs = 50

Dim RTCcmd As Byte

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


schematic is also attached for your reference
 

Attachments

  • rtc-schematic.jpg
    rtc-schematic.jpg
    183.8 KB · Views: 73

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top