18F16Q40 Support Information

XC8-CC #pragma config Usage

#pragma config <setting>=<named value>
For example:
// External Oscillator Selection : EC (external clock) above 8 MHz
// Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
#pragma config FEXTOSC = ECH, RSTOSC = EXTOSC
#pragma config <setting>=<literal constant>
For example:
// External Oscillator Selection : EC (external clock) above 8 MHz
// Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
#pragma config FEXTOSC = 0x7, RSTOSC = 0x7
#pragma config <register>=<literal constant>
For example:
// External Oscillator Selection : EC (external clock) above 8 MHz
// Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
#pragma config CONFIG1 = 0xFF
For example:
// IDLOC @ 0x200000
#pragma config IDLOC0 = 0x65535

PIC-AS config Usage

config "<setting>"="<named value>"
For example:
; External Oscillator Selection : EC (external clock) above 8 MHz
; Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
config "FEXTOSC" = "ECH", "RSTOSC" = "EXTOSC"
config "<setting>"=<literal constant>
For example:
; External Oscillator Selection : EC (external clock) above 8 MHz
; Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
config "FEXTOSC" = 0x7, "RSTOSC" = 0x7
config "<register>"=<literal constant>
For example:
; External Oscillator Selection : EC (external clock) above 8 MHz
; Reset Oscillator Selection : EXTOSC operating per FEXTOSC bits (device manufacturing default)
config "CONFIG1" = 0xFF
For example:
; IDLOC @ 0x200000
config "IDLOC0" = 0x65535

Configuration Registers & Settings

Register: CONFIG1 @ 0x300000
FEXTOSC External Oscillator Selection
LP LP (crystal oscillator) optimized for 32.768 kHz
XT XT (crystal oscillator) above 100 kHz, below 8 MHz
HS HS (crystal oscillator) above 8 MHz
OFF Oscillator not enabled
ECL EC (external clock) below 100 kHz
ECM EC (external clock) for 500 kHz to 8 MHz
ECH EC (external clock) above 8 MHz
RSTOSC Reset Oscillator Selection
HFINTOSC_64MHZ HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
EXTOSC_4PLL EXTOSC with 4x PLL, with EXTOSC operating per FEXTOSC bits
SOSC Secondary Oscillator
LFINTOSC Low-Frequency Oscillator
HFINTOSC_1MHZ HFINTOSC with HFFRQ = 4 MHz and CDIV = 4:1
EXTOSC EXTOSC operating per FEXTOSC bits (device manufacturing default)
Register: CONFIG2 @ 0x300001
CLKOUTEN Clock out Enable bit
OFF CLKOUT function is disabled
ON CLKOUT function is enabled
PR1WAY PRLOCKED One-Way Set Enable bit
ON PRLOCKED bit can be cleared and set only once
OFF PRLOCKED bit can be set and cleared repeatedly
CSWEN Clock Switch Enable bit
OFF The NOSC and NDIV bits cannot be changed by user software
ON Writing to NOSC and NDIV is allowed
FCMEN Fail-Safe Clock Monitor Enable bit
OFF Fail-Safe Clock Monitor disabled
ON Fail-Safe Clock Monitor enabled
FCMENP Fail-Safe Clock Monitor - Primary XTAL Enable bit
OFF Fail-Safe Clock Monitor disabled
ON Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on EXTOSC failure.
FCMENS Fail-Safe Clock Monitor - Secondary XTAL Enable bit
OFF Fail-Safe Clock Monitor Disabled
ON Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on SOSC failure.
Register: CONFIG3 @ 0x300002
MCLRE MCLR Enable bit
EXTMCLR If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
INTMCLR If LVP = 0, MCLR pin function is port defined function; If LVP =1, RE3 pin fuction is MCLR
PWRTS Power-up timer selection bits
PWRT_OFF PWRT is disabled
PWRT_64 PWRT set at 64ms
PWRT_16 PWRT set at 16ms
PWRT_1 PWRT set at 1ms
MVECEN Multi-vector enable bit
ON Multi-vector enabled, Vector table used for interrupts
OFF Interrupt contoller does not use vector table to prioritze interrupts
IVT1WAY IVTLOCK bit One-way set enable bit
ON IVTLOCKED bit can be cleared and set only once
OFF IVTLOCKED bit can be cleared and set repeatedly
LPBOREN Low Power BOR Enable bit
OFF Low-Power BOR disabled
ON Low-Power BOR enabled
BOREN Brown-out Reset Enable bits
SBORDIS Brown-out Reset enabled , SBOREN bit is ignored
NOSLP Brown-out Reset enabled while running, disabled in Sleep; SBOREN is ignored
ON Brown-out Reset enabled according to SBOREN
OFF Brown-out Reset disabled
Register: CONFIG4 @ 0x300003
BORV Brown-out Reset Voltage Selection bits
VBOR_1P9 Brown-out Reset Voltage (VBOR) set to 1.9V
VBOR_2P45 Brown-out Reset Voltage (VBOR) set to 2.45V
VBOR_2P7 Brown-out Reset Voltage (VBOR) set to 2.7V
VBOR_2P85 Brown-out Reset Voltage (VBOR) set to 2.8V
ZCD ZCD Disable bit
OFF ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
ON ZCD module is always enabled; ZCDMD and ZCDSEN bits are ignored
PPS1WAY PPSLOCK bit One-Way Set Enable bit
ON PPSLOCKED bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
OFF PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
STVREN Stack Full/Underflow Reset Enable bit
ON Stack full/underflow will cause Reset
OFF Stack full/underflow will not cause Reset
LVP Low Voltage Programming Enable bit
ON Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
OFF HV on MCLR/VPP must be used for programming
XINST Extended Instruction Set Enable bit
OFF Extended Instruction Set and Indexed Addressing Mode disabled
ON Extended Instruction Set and Indexed Addressing Mode enabled
Register: CONFIG5 @ 0x300004
WDTCPS WDT Period selection bits
WDTCPS_0 Divider ratio 1:32
WDTCPS_1 Divider ratio 1:64
WDTCPS_2 Divider ratio 1:128
WDTCPS_3 Divider ratio 1:256
WDTCPS_4 Divider ratio 1:512
WDTCPS_5 Divider ratio 1:1024
WDTCPS_6 Divider ratio 1:2048
WDTCPS_7 Divider ratio 1:4096
WDTCPS_8 Divider ratio 1:8192
WDTCPS_9 Divider ratio 1:16384
WDTCPS_10 Divider ratio 1:32768
WDTCPS_11 Divider ratio 1:65536
WDTCPS_12 Divider ratio 1:131072
WDTCPS_13 Divider ratio 1:262144
WDTCPS_14 Divider ratio 1:524299
WDTCPS_15 Divider ratio 1:1048576
WDTCPS_16 Divider ratio 1:2097152
WDTCPS_17 Divider ratio 1:4194304
WDTCPS_18 Divider ratio 1:8388608
WDTCPS_19 Divider ratio 1:32
WDTCPS_20 Divider ratio 1:32
WDTCPS_21 Divider ratio 1:32
WDTCPS_22 Divider ratio 1:32
WDTCPS_23 Divider ratio 1:32
WDTCPS_24 Divider ratio 1:32
WDTCPS_25 Divider ratio 1:32
WDTCPS_26 Divider ratio 1:32
WDTCPS_27 Divider ratio 1:32
WDTCPS_28 Divider ratio 1:32
WDTCPS_29 Divider ratio 1:32
WDTCPS_30 Divider ratio 1:32
WDTCPS_31 Divider ratio 1:65536; software control of WDTPS
WDTE WDT operating mode
OFF WDT Disabled; SWDTEN is ignored
SWDTEN WDT enabled/disabled by SWDTEN bit
NSLEEP WDT enabled while sleep=0, suspended when sleep=1; SWDTEN ignored
ON WDT enabled regardless of sleep; SWDTEN is ignored
Register: CONFIG6 @ 0x300005
WDTCWS WDT Window Select bits
WDTCWS_0 window delay = 87.5; no software control; keyed access required
WDTCWS_1 window delay = 75 percent of time; no software control; keyed access required
WDTCWS_2 window delay = 62.5 percent of time; no software control; keyed access required
WDTCWS_3 window delay = 50 percent of time; no software control; keyed access required
WDTCWS_4 window delay = 37.5 percent of time; no software control; keyed access required
WDTCWS_5 window delay = 25 percent of time; no software control; keyed access required
WDTCWS_6 window always open (100%); no software control; keyed access required
WDTCWS_7 window always open (100%); software control; keyed access not required
WDTCCS WDT input clock selector
LFINTOSC WDT reference clock is the 31.0 kHz LFINTOSC
MFINTOSC WDT reference clock is the 31.25kHz MFINTOSC output
SOSC WDT reference clock is SOSC
SC Software Control
Register: CONFIG7 @ 0x300006
BBSIZE Boot Block Size selection bits
BBSIZE_512 Boot Block size is 512 words
BBSIZE_1024 Boot Block size is 1024 words
BBSIZE_2048 Boot Block size is 2048 words
BBSIZE_4096 Boot Block size is 4096 words
BBSIZE_8192 Boot Block size is 8192 words
BBSIZE_16384 Boot Block size is 16384 words
BBEN Boot Block enable bit
OFF Boot block disabled
ON Boot block enabled
SAFEN Storage Area Flash enable bit
OFF SAF disabled
ON SAF enabled
DEBUG Background Debugger
OFF Background Debugger disabled
ON Background Debugger enabled
Register: CONFIG8 @ 0x300007
WRTB Boot Block Write Protection bit
OFF Boot Block not Write protected
ON Boot Block Write protected
WRTC Configuration Register Write Protection bit
OFF Configuration registers not Write protected
ON Configuration registers Write protected
WRTD Data EEPROM Write Protection bit
OFF Data EEPROM not Write protected
ON Data EEPROM Write protected
WRTSAF SAF Write protection bit
OFF SAF not Write Protected
ON SAF Write Protected
WRTAPP Application Block write protection bit
OFF Application Block not write protected
ON Application Block write protected
Register: CONFIG9 @ 0x300008
CP PFM and Data EEPROM Code Protection bit
OFF PFM and Data EEPROM code protection disabled
ON PFM and Data EEPROM code protection enabled
Register: IDLOC0 @ 0x200000
Register: IDLOC1 @ 0x200002
Register: IDLOC2 @ 0x200004
Register: IDLOC3 @ 0x200006
Register: IDLOC4 @ 0x200008
Register: IDLOC5 @ 0x20000A
Register: IDLOC6 @ 0x20000C
Register: IDLOC7 @ 0x20000E
Register: IDLOC8 @ 0x200010
Register: IDLOC9 @ 0x200012
Register: IDLOC10 @ 0x200014
Register: IDLOC11 @ 0x200016
Register: IDLOC12 @ 0x200018
Register: IDLOC13 @ 0x20001A
Register: IDLOC14 @ 0x20001C
Register: IDLOC15 @ 0x20001E
Register: IDLOC16 @ 0x200020
Register: IDLOC17 @ 0x200022
Register: IDLOC18 @ 0x200024
Register: IDLOC19 @ 0x200026
Register: IDLOC20 @ 0x200028
Register: IDLOC21 @ 0x20002A
Register: IDLOC22 @ 0x20002C
Register: IDLOC23 @ 0x20002E
Register: IDLOC24 @ 0x200030
Register: IDLOC25 @ 0x200032
Register: IDLOC26 @ 0x200034
Register: IDLOC27 @ 0x200036
Register: IDLOC28 @ 0x200038
Register: IDLOC29 @ 0x20003A
Register: IDLOC30 @ 0x20003C
Register: IDLOC31 @ 0x20003E

Interrupt Sources

The following table enumerates the IRQ numbers for this device along with descriptions of the interrupt sources. Also shown are the corresponding symbols that can be used as an argument to irq() in the __interrupt() specifier and the macro names that can be used in C source.

For example: __interrupt() specifier usage.
	void __interrupt(irq(SWINT)) isr0(void) { 
		// do stuff
	}
For example: macro usage.
	void __interrupt(irq(default)) isr1(unsigned char irq) {
		switch (irq) {
			case IRQ_HLVD:
				// do HLVD Interrupt stuff
				break;
			case IRQ_OSF:
				// do Oscillator Failure Interrupt stuff
				break;
			case IRQ_CSW:
				// do Clock Switch Interrupt stuff
				break;
			default:
				// do any other stuff
				break;
		}
	}
IRQ __irq() Argument C Device-header Macro Description
0 SWINT IRQ_SWINT Software Interrupt
1 HLVD IRQ_HLVD HLVD Interrupt
2 OSF IRQ_OSF Oscillator Failure Interrupt
3 CSW IRQ_CSW Clock Switch Interrupt
4 NVMIP IRQ_NVMIP N/A
5 CLC1 IRQ_CLC1 CLC1 Interrupt
6 CRC IRQ_CRC CRC Interrupt
7 IOC IRQ_IOC Interrupt on change
8 INT0 IRQ_INT0 External Interrupt 0
9 ZCD IRQ_ZCD ZCD Interrupt
10 AD IRQ_AD ADC Interrupt
11 ACT IRQ_ACT Active Clock Tuning Interrupt
12 CMP1 IRQ_CMP1 Comparator 1 Interrupt
13 SMT1 IRQ_SMT1 SMT1 Interrupt
14 SMT1PRA IRQ_SMT1PRA SMT1 Period Acquisition Interrupt
15 SMT1PWA IRQ_SMT1PWA SMT1 Pulse width acqusition Interrupt
16 ADT IRQ_ADT ADC Threshold Interrupt
20 DMA1SCNT IRQ_DMA1SCNT DMA1 Source count Interrupt
21 DMA1DCNT IRQ_DMA1DCNT DMA1 Destination count Interrupt
22 DMA1OR IRQ_DMA1OR DMA1 Overflow Interrupt
23 DMA1A IRQ_DMA1A DMA1 Abort Interrupt
24 SPI1RX IRQ_SPI1RX SPI1 Receive Interrupt
25 SPI1TX IRQ_SPI1TX SPI1 Transmit Interrupt
26 SPI1 IRQ_SPI1 SPI1 Interrupt
27 TMR2 IRQ_TMR2 Timer2 Interrupt
28 TMR1 IRQ_TMR1 Timer1 Interrupt
29 TMR1G IRQ_TMR1G Timer1 Gate Interrupt
30 CCP1 IRQ_CCP1 CCP1 Interrupt
31 TMR0 IRQ_TMR0 Timer0 Interrupt
32 U1RX IRQ_U1RX UART1 Receive Interrupt
33 U1TX IRQ_U1TX UART1 Transmit Interrupt
34 U1E IRQ_U1E UART1 Error Interrupt
35 U1 IRQ_U1 UART1 Interrupt
36 TMR3 IRQ_TMR3 Timer3 Interrupt
37 TMR3G IRQ_TMR3G Timer3 Gate Interrupt
38 PWM1PR IRQ_PWM1PR PWM1 Period Interrupt
39 PWM1 IRQ_PWM1 PWM1 Interrupt
40 SPI2RX IRQ_SPI2RX SPI2 Receive Interrupt
41 SPI2TX IRQ_SPI2TX SPI2 Transmit Interrupt
42 SPI2 IRQ_SPI2 SPI2 Interrupt
44 CMP2 IRQ_CMP2 Comparator 2 Interrupt
45 CLC2 IRQ_CLC2 CLC2 Interrupt
46 PWM2PR IRQ_PWM2PR PWM2 Period Interrupt
47 PWM2 IRQ_PWM2 PWM2 Interrupt
48 INT1 IRQ_INT1 External Interrupt 1
49 CWG1 IRQ_CWG1 CWG Interrupt
50 NCO1 IRQ_NCO1 NCO1 Interrupt
51 DMA2SCNT IRQ_DMA2SCNT DMA2 Source count Interrupt
52 DMA2DCNT IRQ_DMA2DCNT DMA2 Destination count Interrupt
53 DMA2OR IRQ_DMA2OR DMA2 Overflow Interrupt
54 DMA2A IRQ_DMA2A DMA2 Abort Interrupt
56 I2C1RX IRQ_I2C1RX I2C1 Receive Interrupt
57 I2C1TX IRQ_I2C1TX I2C1 Transmit Interrupt
58 I2C1 IRQ_I2C1 I2C1 Interrupt
59 I2C1E IRQ_I2C1E I2C1 Error Interrupt
61 CLC3 IRQ_CLC3 CLC3 Interrupt
62 PWM3PR IRQ_PWM3PR PWM3 Period Interrupt
63 PWM3 IRQ_PWM3 PWM3 Interrupt
64 U2RX IRQ_U2RX UART2 Receive Interrupt
65 U2TX IRQ_U2TX UART2 Transmit Interrupt
66 U2E IRQ_U2E UART2 Error Interrupt
67 U2 IRQ_U2 UART2 Interrupt
69 CLC4 IRQ_CLC4 CLC4 Interrupt
71 SCAN IRQ_SCAN Scanner Interrupt
72 U3RX IRQ_U3RX UART3 Receive Interrupt
73 U3TX IRQ_U3TX UART3 Transmit Interrupt
74 U3E IRQ_U3E UART3 Error Interrupt
75 U3 IRQ_U3 UART3 Interrupt
76 DMA3SCNT IRQ_DMA3SCNT DMA3 Source count Interrupt
77 DMA3DCNT IRQ_DMA3DCNT DMA3 Destination count Interrupt
78 DMA3OR IRQ_DMA3OR DMA3 Overflow Interrupt
79 DMA3A IRQ_DMA3A DMA3 Abort Interrupt
80 INT2 IRQ_INT2 External Interrupt 2
83 TMR4 IRQ_TMR4 Timer4 Interrupt
84 DMA4SCNT IRQ_DMA4SCNT DMA4 Source count Interrupt
85 DMA4DCNT IRQ_DMA4DCNT DMA4 Destination count Interrupt
86 DMA4OR IRQ_DMA4OR DMA4 Overflow Interrupt
87 DMA4A IRQ_DMA4A DMA4 Abort Interrupt