I'm just back from holiday, and was mostly without Internet access. I
have been working 'offline' on a library for the RTCC module (destined
for a timer based on a 18f26j11). Do we have a duplicate and/or could we
combine the efforts? I have not done any real testing yet.
Regards, Rob.
Hi Rob,
I don't have a library in jallib acception, however routines below works OK
for me.
I didn't write any alarm routine, but are quite similar with RTCC time
routines.
Vasile
--------------------------------------------------------
-- RTCC cfg settings
--------------------------------------------------------
;assembler
; movlb 15
;movlw 0x55
;movwf EECON2
;movlw 0xAA
;movwf EECON2
;bsf RTCCFG_RTCWREN
;end assembler
const bit RTC_enabled = 1
const bit RTC_disabled = 0
procedure RTC_writing (bit in value) is
RTCCFG_RTCWREN = value -- 1 enabled, 0 disabled
EECON2 = 0x55 -- \ required sequence
EECON2 = 0xAA -- /
RTCCFG_RTCWREN = 1 ; allow writting to RTCCFG
end procedure
RTC_writing (RTC_enabled)
RTCCFG_RTCEN = 1 ; enable RTCC
RTCCFG_RTCOE = 0 ; RTCC output disabled
PADCFG1_RTSECSEL1 = 0
PADCFG1_RTSECSEL0 = 1 ; RTCC seconds clock selected on RTCCpin
ALRMCFG_ALRMEN = 0 ; alarm disabled
RTC_writing (RTC_disabled)
-- variables, some of them not used here
------------------------------------------------------------------------------------------------------
var byte hour, H1, H2, minute, M1, M2, second, S1, S2, _1st_second,
_2st_second
var byte year, y2, y1, month, mo2, mo1, day, d2, d1
var byte hour_prg, Hp1, Hp2, minute_prg, Mp1, Mp2, second_prg, Sp1, Sp2
var byte minute_trt, minute_trt_prg, second_trt, second_trt_prg
var bit block_halfsec = high
minute_trt = 30
second_trt = 0
var sbyte char_position = 2
var bit line_position_flag = low
-------------------------------------------------------------------------------------------------------
-- set hour=0
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 1
RTCVALL = 0
-- set minute=0
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
RTCVALH = 0
-- set seconds=0
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
RTCVALL = 0
-------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- read RTCC time
------------------------------------------------------------------------------------------------------
procedure read_time () is
-- read hour
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 1
if RTCCFG_RTCSYNC == 0 then
hour = RTCVALL
end if
;H2 = (hour & 0b0000_1111) + 0x30
;H1 = ((hour >> 4) & 0b0000_1111) + 0x30
-- read minute
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
if RTCCFG_RTCSYNC == 0 then
minute = RTCVALH
end if
;M2 = (minute & 0b0000_1111) + 0x30
;M1 = ((minute >> 4) & 0b0000_1111) + 0x30
-- read seconds
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
if RTCCFG_RTCSYNC == 0 then
second = RTCVALL
end if
;S2 = (second & 0b0000_1111) + 0x30
;S1 = ((second >> 4) & 0b0000_1111) + 0x30
end procedure
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- compute ASCII RTCC time
----------------------------------------------------------------------------------------------------------
procedure compute_time_ASCII ()is
H2 = (hour & 0b0000_1111) + 0x30
H1 = ((hour >> 4) & 0b0000_1111) + 0x30
M2 = (minute & 0b0000_1111) + 0x30
M1 = ((minute >> 4) & 0b0000_1111) + 0x30
S2 = (second & 0b0000_1111) + 0x30
S1 = ((second >> 4) & 0b0000_1111) + 0x30
end procedure
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- write RTCC time
----------------------------------------------------------------------------------------------------------
procedure write_time (byte in hour_prg, byte in minute_prg, byte in
second_prg) is
RTC_writing (RTC_enabled)
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 1
Hp2 = hour_prg/c10 ; convert to bcd
Hp2 = Hp2 << 4 ; rotate left
Hp1 = hour_prg%c10 ; convert to bcd
hour_prg = Hp2 + Hp1 ; Hp2Hp1:Mp2Mp1:Sp2Sp1 format
RTCVALL = hour_prg
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
Mp2 = minute_prg/c10
Mp2 = Mp2 << 4
Mp1 = minute_prg%c10
minute_prg = Mp2 + Mp1
RTCVALH = minute_prg
RTCCFG_RTCPTR1 = 0
RTCCFG_RTCPTR0 = 0
Sp2 = second_prg/c10
Sp2 = Sp2 << 4
Sp1 = second_prg%c10
second_prg = Sp2 + Sp1
RTCVALL = second_prg
RTC_writing (RTC_disabled)
end procedure
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-- read ASCII RTCC calendar
-------------------------------------------------------------------------------------------------------
procedure read_calendar () is
-- read year
RTCCFG_RTCPTR1 = 1
RTCCFG_RTCPTR0 = 1
year = RTCVALL
y2 = (year & 0b0000_1111) + 0x30
y1 = ((year >> 4) & 0b0000_1111) + 0x30
-- read month
RTCCFG_RTCPTR1 = 1
RTCCFG_RTCPTR0 = 0
month = RTCVALH
mo2 = (month & 0b0000_1111) + 0x30
mo1 = ((month >> 4) & 0b0000_1111) + 0x30
-- read day
RTCCFG_RTCPTR1 = 1
RTCCFG_RTCPTR0 = 0
day = RTCVALL
d2 = (day & 0b0000_1111) + 0x30
d1 = ((day >> 4) & 0b0000_1111) + 0x30
end procedure
-------------------------------------------------------------------------------------------------------
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.