Part2...
end of part 2...Code:'----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- '---ENOUGH SETUP, LET'S GET STARTED................ HPWM 1, contrast, 500 'set the LCD contrast Pause 1000 'wait for the LCD to wake up lcdout $fe, 1 'Clear LCD asm ;This bit of code turns ON the RTC WRITE ENABLE. It MUST be done in ASM... RTFM- "16.2.7 WRITE LOCK", "SETTING THE RTCWREN BIT" movlb 0x0F ;RTCCFG is banked bcf INTCON, GIE ;Disable interrupts movlw 0x55 movwf EECON2 movlw 0xAA movwf EECON2 bsf RTCCFG,RTCWREN endasm RTCCFG.7 = 1 'turn on the RTCC module '!!!!!!!!!!!!!!!!!!!USER SETTING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '---USER CAN SET THE CLOCK HERE---------------------------- year = 10 '(last 2 digits of the millenium, 0-99) month = 03 '(1-12) day = 26 '(1-31) hours = 19 '(0-23) minutes = 29 '(0-59) seconds = 00 '(0-59) weekdaynum = 6 '(0-6) (0=sunday, 1= monday, etc) '!!!!!!!!!!!!!!!!!//USER SETTING//!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '---------------------------------------------------------- Gosub settime 'put the user settings into the time registers RTCCFG.5 = 0 'disable RTC write enable goto main 'skip the subroutines and JGIG '--SUBROUTINES!---------------------------------------------------------------- '---SUBROUTINE TO CONVERT USER ENTRY TO BCD AND LOAD THE TIME REGISTERS--------- settime: '------(RTCPTR<1:0> automatically decrements by 1 each time RTCVALH is read or written to) RTFM, TABLE 16-3-------- RTCCFG.1 = 1 'set RTCPTR1 RTCCFG.0 = 1 'set RTCPTR0 rtcvall = year dig 1 *16 + year dig 0 'set year rtcvalh = 00 'unused... just send something to rtcvalh so it will increment the pointer rtcvall= day dig 1 *16 + day dig 0 'set day rtcvalh = month dig 1 *16 + month dig 0 'set month rtcvall= hours dig 1 *16 + hours dig 0 'set hours rtcvalh = weekdaynum 'set weekday (0-6) rtcvall= seconds dig 1 *16 + seconds dig 0 'set seconds rtcvalh = minutes dig 1 *16 + minutes dig 0 'set minutes return '----------------------------------------- '---SUBROUTINE TO CONVERT THE BCD FOR EASY DISPLAY---------- convertBCD: timevall = ((timevall/16)*10)+(timevall & %00001111) timevalh = ((timevalh/16)*10)+(timevalh & %00001111) return '------------------------------------------ '---SUBROUTINE TO CONVERT MONTH NUMBER TO REAL TEXT------------------- decodemonth: 'there's GOT to be a better way to convert an index number to a string... if month = 1 then monthname[0] = "J": monthname[1] = "A": monthname[2] = "N" if month = 2 then monthname[0] = "F": monthname[1] = "E": monthname[2] = "B" if month = 3 then monthname[0] = "M": monthname[1] = "A": monthname[2] = "R" if month = 4 then monthname[0] = "A": monthname[1] = "P": monthname[2] = "R" if month = 5 then monthname[0] = "M": monthname[1] = "A": monthname[2] = "Y" if month = 6 then monthname[0] = "J": monthname[1] = "U": monthname[2] = "N" if month = 7 then monthname[0] = "J": monthname[1] = "U": monthname[2] = "L" if month = 8 then monthname[0] = "A": monthname[1] = "U": monthname[2] = "G" if month = 9 then monthname[0] = "S": monthname[1] = "E": monthname[2] = "P" if month = 10 then monthname[0] = "O": monthname[1] = "C": monthname[2] = "T" if month = 11 then monthname[0] = "N": monthname[1] = "O": monthname[2] = "V" if month = 12 then monthname[0] = "D": monthname[1] = "E": monthname[2] = "C" return '----------------------------------------------------------------------------------- '---[/subroutines]--------------------------------------------------------- '----------------------------------------------------------------------- '---MAIN PROGRAM-------------------------------------------------------- Main: '---set RTCPTR1 & RTCPTR2 to 11--- RTCCFG.1 = 1 'set RTCPTR1 (RTCPTR<1:0> automatically decrements by 1 each time RTCVALH is read or written to) RTFM, TABLE 16-3-------- RTCCFG.0 = 1 'set RTCPTR0 '---get year--- timevall = rtcvall timevalh = rtcvalh gosub convertBCD year = timevall '---get month and day--- timevall = rtcvall timevalh = rtcvalh gosub convertBCD month = timevalh day = timevall '---get weekday and hours--- timevall = rtcvall timevalh = rtcvalh gosub convertBCD weekdaynum = timevalh hours = timevall '---get minutes and seconds--- timevall = rtcvall timevalh = rtcvalh gosub convertBCD minutes = timevalh seconds = timevall '---do the 24/12 hour dance--- If hours > 11 then pmflag = "P" else pmflag = "A" endif if hours > 12 then hours = hours - 12 if hours = 0 then hours = 12 gosub decodemonth '---display it all--- lcdout $fe,2," ",dec hours,":",DEC2 minutes,":",Dec2 seconds," ",pmflag,"M ",$fe,$c0," ",STR monthname\3," ",dec day,", 20",dec year pause 30 'Slow down you move too fast, You've got to make the morning last. Just skippin' down the cobble stones, Lookin' for fun and feelin' groovy goto main end




Bookmarks