This was tested on a PIC18F25J11 running at 3V, but should work on your 46J11. Note it was tested with PBP3, but can easily be modified to work with earlier versions.
Code:
#CONFIG
CONFIG OSC = INTOSC
CONFIG LPT1OSC = OFF
CONFIG CP0 = OFF
CONFIG WDTEN = OFF
CONFIG XINST = OFF
CONFIG IOL1WAY = OFF
CONFIG STVREN = OFF
CONFIG T1DIG = OFF
CONFIG FCMEN = OFF
CONFIG WDTPS = 512
CONFIG RTCOSC = T1OSCREF
#ENDCONFIG
' Connect a 32.768 kHz watch crystal between pins 11 & 12 T1CKI & T1OSI
' with caps to match your crystal capacitance.
' 11 12
' |---||---|
' | xtal |
' _|_ _|_
' ___ ___ 2 x 12pF caps
' | |
' gnd gnd
DEFINE OSC 4
OSCCON = %01100000 ' using 4MHz internal osc
' // disable A/D & setup Timer1 for RTCC //
ANCON0 = $ff
ANCON1 = $1f ' disable A/D on all analog pins
T1CON = %10001101 ' ext 32.768 kHz xtal, 1:1 prescale, no synch, 8-bit, timer1 on
TRISB.1 = 0 ' clear TRISB.1 for RTCC 1Hz output
PADCFG1 = %00000010 ' RTCC seconds clock is selected for output on the RTCC pin
RTCCFG.2 = 1 ' set RTCC output enable bit
EECON2 = $55 ' unlock sequence to enable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 1 ' set bit 5 for RTCC write enable
RTCCFG.7 = 1 ' set bit 7 for RTCC clock enable
EECON2 = $55 ' lock sequence to disable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 0 ' clear bit 5 to lockup & disable RTCC writes
Here:
GOTO Here
END
It produces a very accurate 1Hz clock out on RB1.
This is a working test version of a serial clock & 3 x 10KHz PWM outputs with the same PIC CLOCK_25J11.txt
Hope this helps.
Bookmarks