
_interrupt:

;RTCC.mbas,16 :: 		sub procedure interrupt
;RTCC.mbas,17 :: 		USB_Interrupt_Proc()
	CALL        _USB_Interrupt_Proc+0, 0
;RTCC.mbas,18 :: 		end sub
L_end_interrupt:
L__interrupt22:
	RETFIE      1
; end of _interrupt

_RTCC_WrEn:

;RTCC.mbas,20 :: 		sub procedure RTCC_WrEn 'Enables writing to the RTCC registers
;RTCC.mbas,21 :: 		EECON2 = 0x55
	MOVLW       85
	MOVWF       EECON2+0 
;RTCC.mbas,22 :: 		EECON2 = 0xAA
	MOVLW       170
	MOVWF       EECON2+0 
;RTCC.mbas,23 :: 		RTCWREN_bit = 1
	BSF         RTCWREN_bit+0, BitPos(RTCWREN_bit+0) 
;RTCC.mbas,24 :: 		end sub
L_end_RTCC_WrEn:
	RETURN      0
; end of _RTCC_WrEn

_RTCC_Read:

;RTCC.mbas,26 :: 		sub procedure RTCC_Read() 'Reads from the RTCC
;RTCC.mbas,27 :: 		RTCCFG = %10000011 'Set RTCPTR to 11
	MOVLW       131
	MOVWF       RTCCFG+0 
;RTCC.mbas,28 :: 		while RTCSYNC_bit = 1
L__RTCC_Read4:
	BTFSC       RTCSYNC_bit+0, BitPos(RTCSYNC_bit+0) 
	GOTO        L__RTCC_Read4
;RTCC.mbas,31 :: 		bytYear   = Bcd2Dec(RTCVALL)
	MOVF        RTCVALL+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytYear+0 
;RTCC.mbas,32 :: 		bytMonth  = Bcd2Dec(RTCVALH) 'Just to decrement RTCPTR
	MOVF        RTCVALH+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytMonth+0 
;RTCC.mbas,33 :: 		bytDay    = Bcd2Dec(RTCVALL)
	MOVF        RTCVALL+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytDay+0 
;RTCC.mbas,34 :: 		bytMonth  = Bcd2Dec(RTCVALH)
	MOVF        RTCVALH+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytMonth+0 
;RTCC.mbas,35 :: 		bytHour   = Bcd2Dec(RTCVALL)
	MOVF        RTCVALL+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytHour+0 
;RTCC.mbas,36 :: 		bytWkDay  = Bcd2Dec(RTCVALH)
	MOVF        RTCVALH+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytWkDay+0 
;RTCC.mbas,37 :: 		bytSecond = Bcd2Dec(RTCVALL)
	MOVF        RTCVALL+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytSecond+0 
;RTCC.mbas,38 :: 		bytMinute = Bcd2Dec(RTCVALH)
	MOVF        RTCVALH+0, 0 
	MOVWF       FARG_Bcd2Dec_bcd_num+0 
	CALL        _Bcd2Dec+0, 0
	MOVF        R0, 0 
	MOVWF       _bytMinute+0 
;RTCC.mbas,39 :: 		end sub
L_end_RTCC_Read:
	RETURN      0
; end of _RTCC_Read

_RTCC_Write:

;RTCC.mbas,41 :: 		sub procedure RTCC_Write() 'Writes to the RTCC
;RTCC.mbas,42 :: 		RTCC_WrEn
	CALL        _RTCC_WrEn+0, 0
;RTCC.mbas,43 :: 		RTCCFG = %10100011 'Set RTCPTR to 11
	MOVLW       163
	MOVWF       RTCCFG+0 
;RTCC.mbas,44 :: 		RTCVALL = Dec2Bcd(bytYear)
	MOVF        _bytYear+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALL+0 
;RTCC.mbas,45 :: 		RTCVALH = Dec2Bcd(bytMonth) 'Just to decrement RTCPTR
	MOVF        _bytMonth+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALH+0 
;RTCC.mbas,46 :: 		RTCVALL = Dec2Bcd(bytDay)
	MOVF        _bytDay+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALL+0 
;RTCC.mbas,47 :: 		RTCVALH = Dec2Bcd(bytMonth)
	MOVF        _bytMonth+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALH+0 
;RTCC.mbas,48 :: 		RTCVALL = Dec2Bcd(bytHour)
	MOVF        _bytHour+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALL+0 
;RTCC.mbas,49 :: 		RTCVALH = Dec2Bcd(bytWkDay)
	MOVF        _bytWkDay+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALH+0 
;RTCC.mbas,50 :: 		RTCVALL = Dec2Bcd(bytSecond)
	MOVF        _bytSecond+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALL+0 
;RTCC.mbas,51 :: 		RTCVALH = Dec2Bcd(bytMinute)
	MOVF        _bytMinute+0, 0 
	MOVWF       FARG_Dec2Bcd_decnum+0 
	CALL        _Dec2Bcd+0, 0
	MOVF        R0, 0 
	MOVWF       RTCVALH+0 
;RTCC.mbas,52 :: 		RTCWREN_bit = 0
	BCF         RTCWREN_bit+0, BitPos(RTCWREN_bit+0) 
;RTCC.mbas,53 :: 		end sub
L_end_RTCC_Write:
	RETURN      0
; end of _RTCC_Write

_GenerateDigits:

;RTCC.mbas,55 :: 		sub procedure GenerateDigits(dim value as byte, dim pos as ^char)
;RTCC.mbas,56 :: 		pos^ = (value div 10) + 48
	MOVLW       10
	MOVWF       R4 
	MOVF        FARG_GenerateDigits_value+0, 0 
	MOVWF       R0 
	CALL        _Div_8x8_U+0, 0
	MOVFF       FARG_GenerateDigits_pos+0, FSR1
	MOVFF       FARG_GenerateDigits_pos+1, FSR1H
	MOVLW       48
	ADDWF       R0, 0 
	MOVWF       POSTINC1+0 
;RTCC.mbas,57 :: 		Inc(pos)
	INFSNZ      FARG_GenerateDigits_pos+0, 1 
	INCF        FARG_GenerateDigits_pos+1, 1 
;RTCC.mbas,58 :: 		pos^ = (value mod 10) + 48
	MOVLW       10
	MOVWF       R4 
	MOVF        FARG_GenerateDigits_value+0, 0 
	MOVWF       R0 
	CALL        _Div_8x8_U+0, 0
	MOVF        R8, 0 
	MOVWF       R0 
	MOVFF       FARG_GenerateDigits_pos+0, FSR1
	MOVFF       FARG_GenerateDigits_pos+1, FSR1H
	MOVLW       48
	ADDWF       R0, 0 
	MOVWF       POSTINC1+0 
;RTCC.mbas,59 :: 		end sub
L_end_GenerateDigits:
	RETURN      0
; end of _GenerateDigits

_GenerateRTCCString:

;RTCC.mbas,62 :: 		dim pos as ^char
;RTCC.mbas,63 :: 		pos = @rtccstring
	MOVF        FARG_GenerateRTCCString_rtccstring+0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        FARG_GenerateRTCCString_rtccstring+1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,64 :: 		rtccstring = "00-00-00 00:00:00"
	MOVF        FARG_GenerateRTCCString_rtccstring+0, 0 
	MOVWF       FSR1 
	MOVF        FARG_GenerateRTCCString_rtccstring+1, 0 
	MOVWF       FSR1H 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       45
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       45
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       32
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       58
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       58
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	MOVLW       48
	MOVWF       POSTINC1+0 
	CLRF        POSTINC1+0 
;RTCC.mbas,65 :: 		GenerateDigits(bytYear, pos)
	MOVF        _bytYear+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        GenerateRTCCString_pos+0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        GenerateRTCCString_pos+1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,66 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,67 :: 		GenerateDigits(bytMonth, pos)
	MOVF        _bytMonth+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        R0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        R1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,68 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,69 :: 		GenerateDigits(bytDay, pos)
	MOVF        _bytDay+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        R0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        R1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,70 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,71 :: 		GenerateDigits(bytHour, pos)
	MOVF        _bytHour+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        R0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        R1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,72 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,73 :: 		GenerateDigits(bytMinute, pos)
	MOVF        _bytMinute+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        R0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        R1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,74 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,75 :: 		GenerateDigits(bytSecond, pos)
	MOVF        _bytSecond+0, 0 
	MOVWF       FARG_GenerateDigits_value+0 
	MOVF        R0, 0 
	MOVWF       FARG_GenerateDigits_pos+0 
	MOVF        R1, 0 
	MOVWF       FARG_GenerateDigits_pos+1 
	CALL        _GenerateDigits+0, 0
;RTCC.mbas,76 :: 		pos = pos + 3
	MOVLW       3
	ADDWF       GenerateRTCCString_pos+0, 0 
	MOVWF       R0 
	MOVLW       0
	ADDWFC      GenerateRTCCString_pos+1, 0 
	MOVWF       R1 
	MOVF        R0, 0 
	MOVWF       GenerateRTCCString_pos+0 
	MOVF        R1, 0 
	MOVWF       GenerateRTCCString_pos+1 
;RTCC.mbas,77 :: 		pos^ = 0
	MOVFF       R0, FSR1
	MOVFF       R1, FSR1H
	CLRF        POSTINC1+0 
;RTCC.mbas,78 :: 		end sub
L_end_GenerateRTCCString:
	RETURN      0
; end of _GenerateRTCCString

_USB_RTCC:

;RTCC.mbas,80 :: 		sub procedure USB_RTCC
;RTCC.mbas,81 :: 		GenerateRTCCString(USBout)
	MOVLW       _USBout+0
	MOVWF       FARG_GenerateRTCCString_rtccstring+0 
	MOVLW       hi_addr(_USBout+0)
	MOVWF       FARG_GenerateRTCCString_rtccstring+1 
	CALL        _GenerateRTCCString+0, 0
;RTCC.mbas,82 :: 		strcat(USBout, chr(13) + chr(10))
	MOVLW       _USBout+0
	MOVWF       FARG_strcat_s1+0 
	MOVLW       hi_addr(_USBout+0)
	MOVWF       FARG_strcat_s1+1 
	MOVLW       13
	MOVWF       ?LocalText_USB_RTCC_0+0 
	MOVLW       10
	MOVWF       ?LocalText_USB_RTCC_0+1 
	MOVLW       0
	MOVWF       ?LocalText_USB_RTCC_0+2 
	MOVLW       ?LocalText_USB_RTCC_0+0
	MOVWF       FARG_strcat_s2+0 
	MOVLW       hi_addr(?LocalText_USB_RTCC_0+0)
	MOVWF       FARG_strcat_s2+1 
	CALL        _strcat+0, 0
;RTCC.mbas,83 :: 		HID_Write(@USBout, 64)
	MOVLW       _USBout+0
	MOVWF       FARG_HID_Write_writebuff+0 
	MOVLW       hi_addr(_USBout+0)
	MOVWF       FARG_HID_Write_writebuff+1 
	MOVLW       64
	MOVWF       FARG_HID_Write_len+0 
	CALL        _HID_Write+0, 0
;RTCC.mbas,84 :: 		end sub
L_end_USB_RTCC:
	RETURN      0
; end of _USB_RTCC

_TestRTCC_Write:

;RTCC.mbas,86 :: 		sub procedure TestRTCC_Write
;RTCC.mbas,87 :: 		bytYear = 12
	MOVLW       12
	MOVWF       _bytYear+0 
;RTCC.mbas,88 :: 		bytMonth = 08
	MOVLW       8
	MOVWF       _bytMonth+0 
;RTCC.mbas,89 :: 		bytDay = 19
	MOVLW       19
	MOVWF       _bytDay+0 
;RTCC.mbas,90 :: 		bytHour = 16
	MOVLW       16
	MOVWF       _bytHour+0 
;RTCC.mbas,91 :: 		bytMinute = 59
	MOVLW       59
	MOVWF       _bytMinute+0 
;RTCC.mbas,92 :: 		bytSecond = 55
	MOVLW       55
	MOVWF       _bytSecond+0 
;RTCC.mbas,93 :: 		RTCC_Write
	CALL        _RTCC_Write+0, 0
;RTCC.mbas,94 :: 		end sub
L_end_TestRTCC_Write:
	RETURN      0
; end of _TestRTCC_Write

_main:

;RTCC.mbas,96 :: 		main:
;RTCC.mbas,97 :: 		OSCCON = %01110000 '8MHz
	MOVLW       112
	MOVWF       OSCCON+0 
;RTCC.mbas,98 :: 		PLLEn_bit = 1 'PLL enabled (now 48MHz)
	BSF         PLLEN_bit+0, BitPos(PLLEN_bit+0) 
;RTCC.mbas,101 :: 		T1OSCEN_bit = 1
	BSF         T1OSCEN_bit+0, BitPos(T1OSCEN_bit+0) 
;RTCC.mbas,102 :: 		RTCC_WrEn
	CALL        _RTCC_WrEn+0, 0
;RTCC.mbas,103 :: 		RTCEN_bit = 1
	BSF         RTCEN_bit+0, BitPos(RTCEN_bit+0) 
;RTCC.mbas,104 :: 		RTCWREN_Bit = 0
	BCF         RTCWREN_bit+0, BitPos(RTCWREN_bit+0) 
;RTCC.mbas,106 :: 		HID_Enable(@USBin, @USBout)
	MOVLW       _USBin+0
	MOVWF       FARG_HID_Enable_readbuff+0 
	MOVLW       hi_addr(_USBin+0)
	MOVWF       FARG_HID_Enable_readbuff+1 
	MOVLW       _USBout+0
	MOVWF       FARG_HID_Enable_writebuff+0 
	MOVLW       hi_addr(_USBout+0)
	MOVWF       FARG_HID_Enable_writebuff+1 
	CALL        _HID_Enable+0, 0
;RTCC.mbas,107 :: 		USBout = "SimPLC RTCC" + chr(13) + chr(10)
	MOVLW       83
	MOVWF       1344 
	MOVLW       105
	MOVWF       1345 
	MOVLW       109
	MOVWF       1346 
	MOVLW       80
	MOVWF       1347 
	MOVLW       76
	MOVWF       1348 
	MOVLW       67
	MOVWF       1349 
	MOVLW       32
	MOVWF       1350 
	MOVLW       82
	MOVWF       1351 
	MOVLW       84
	MOVWF       1352 
	MOVLW       67
	MOVWF       1353 
	MOVLW       67
	MOVWF       1354 
	MOVLW       13
	MOVWF       1355 
	MOVLW       10
	MOVWF       1356 
	MOVLW       0
	MOVWF       1357 
;RTCC.mbas,108 :: 		HID_Write(@USBout, 64)
	MOVLW       _USBout+0
	MOVWF       FARG_HID_Write_writebuff+0 
	MOVLW       hi_addr(_USBout+0)
	MOVWF       FARG_HID_Write_writebuff+1 
	MOVLW       64
	MOVWF       FARG_HID_Write_len+0 
	CALL        _HID_Write+0, 0
;RTCC.mbas,110 :: 		TestRTCC_Write()
	CALL        _TestRTCC_Write+0, 0
;RTCC.mbas,112 :: 		TRISD4_bit = 0
	BCF         TRISD4_bit+0, BitPos(TRISD4_bit+0) 
;RTCC.mbas,113 :: 		LATD4_bit = 0
	BCF         LATD4_bit+0, BitPos(LATD4_bit+0) 
;RTCC.mbas,115 :: 		while(1)
L__main15:
;RTCC.mbas,116 :: 		LATD4_bit = 1
	BSF         LATD4_bit+0, BitPos(LATD4_bit+0) 
;RTCC.mbas,117 :: 		RTCC_Read()
	CALL        _RTCC_Read+0, 0
;RTCC.mbas,118 :: 		USB_RTCC()
	CALL        _USB_RTCC+0, 0
;RTCC.mbas,119 :: 		delay_ms(100)
	MOVLW       7
	MOVWF       R11, 0
	MOVLW       23
	MOVWF       R12, 0
	MOVLW       106
	MOVWF       R13, 0
L__main19:
	DECFSZ      R13, 1, 1
	BRA         L__main19
	DECFSZ      R12, 1, 1
	BRA         L__main19
	DECFSZ      R11, 1, 1
	BRA         L__main19
	NOP
;RTCC.mbas,120 :: 		LATD4_bit = 0
	BCF         LATD4_bit+0, BitPos(LATD4_bit+0) 
;RTCC.mbas,121 :: 		delay_ms(900)
	MOVLW       55
	MOVWF       R11, 0
	MOVLW       202
	MOVWF       R12, 0
	MOVLW       211
	MOVWF       R13, 0
L__main20:
	DECFSZ      R13, 1, 1
	BRA         L__main20
	DECFSZ      R12, 1, 1
	BRA         L__main20
	DECFSZ      R11, 1, 1
	BRA         L__main20
;RTCC.mbas,122 :: 		wend
	GOTO        L__main15
L_end_main:
	GOTO        $+0
; end of _main
