Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Alarm Clock using oshonsoft

Status
Not open for further replies.
I take it you want to put a DS1307 on the I2C bus... Here is my DS1307 I2C code using Oshonsoft (If you don't have the use of functions, you may need to change the two sorting routines)

Code:
Symbol sda = PORTC.4  'SDA pin
Symbol scl = PORTC.3  'SCL pin

Const rtc = 0xd0
Dim time(7) As Byte
Dim index As Byte

main:

	'Your code
goto main
end

'Retrieve time values
'----------------------
getdatetime:
	For index = 0 To 6
		I2CRead sda, scl, rtc, index, time(index)
		time(index) = rtc_sort(time(index))
		WaitMs 1
	Next index
Return                                            

'Set time values
'-----------------
setdatetime:
	For index = 0 To 6
		time(index) = rtc_unsort(time(index))
		I2CWrite sda, scl, rtc, index, time(index)
		WaitMs 10
	Next index
Return                                            

'Unsort time for RTC display array
'-----------------------------------
Function rtc_unsort(dta As Byte) As Byte
	d_hi = dta / 10
	d_lo = dta Mod 10
	rtc_unsort = d_hi * 16 + d_lo
End Function                                      

'Sort time for RTC ram banks
'-----------------------------
Function rtc_sort(dta As Byte) As Byte
	d_hi = ShiftRight(dta, 4)
	d_hi = d_hi And 7
	d_lo = dta Mod 16
	rtc_sort = d_hi * 10 + d_lo
End Function

You can now just poll getdatetime every cycle and biuld your alarm clock around this code
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top