;*************************************************************************** ;* Name : ALLDIGITAL.pbp * ;* Author : Darrel Taylor * ;* Notice : Copyright (c) 2009 * ;* : All Rights Reserved until Abused * ;* Date : 4/30/2009 * ;* Version : 1.5 (3/7/2011) * ;* Notes : An INCLUDE file that will automatically enable * ;* : all DIGITAL Inputs multiplexed with the ADC or Comparators * ;* : Works with ANY PIC, using either PM or MPASM * ;*************************************************************************** ;* Useage : INCLUDE "AllDigital.pbp" * ;* : yup, that's it. Just include the file and it's All Digital * ;* : Adding this line to your program will display the values * ;* : used to achieve AllDigital ... (if using MPASM) * ;* : DEFINE SHOWDIGITAL 1 * ;*************************************************************************** ;* Versions: 1.0 - Initial release * ;* 5/6/2009 : 1.1 - Added Shared address SFR support for 18F87J50 family * ;* : Thanks to mister_e * ;* 5/9/2009 : 1.2 - Removed MPASM specific opcode (variable), for PM.exe * ;* : Thanks to Tobias * ;* 7/11/2009: 1.3 - Added ANSELA,ANSELB,ANSELD,ANSELE for the 16F72x series* ;* 7/19/2010: 1.4 - Added ANSEL0 and ANSEL1 for the 18F4431 series. * ;* 3/7/2011: 1.5 - Update for latest chips from Microchip * ;*************************************************************************** ;Check 18F45k80 ---- ; Uses ANCONx with ANSEL0 and ANSEL1 as bit names ; other PIC's have ANSEL0 and ANSEL1 ASM ;----[Module defaults]------------------------------------------------------ #define SHOWDIGITALDEFAULT 0 ifdef SHOWDIGITAL SHOWDIGITALRESULT = SHOWDIGITAL else SHOWDIGITALRESULT = SHOWDIGITALDEFAULT endif ifndef PM_USED ifndef ADLISTALL nolist endif endif ;----[Attempt to Set a registers Value]------------------------------------- SetReg macro RegOut, Cin ifndef PM_USED ifndef ADLISTALL nolist endif endif ifdef RegOut ifndef PM_USED list endif MOVE?CB Cin, RegOut if (SHOWDIGITALRESULT == 1) ifndef PM_USED messg RegOut = Cin endif endif ifndef PM_USED ifndef ADLISTALL nolist endif endif endif endm ;----[A/D Converter registers]---------------------------------------------- HasANSEL = 0 ifdef ANSEL HasANSEL = 1 SetReg ANSEL , 0 ; if chip has ANSEL's, clear them endif ifdef ANSEL0 ifndef ANCON0 HasANSEL = 1 SetReg ANSEL0, 0 endif endif ifdef ANSEL1 ifndef ANCON0 HasANSEL = 1 SetReg ANSEL1, 0 endif endif ifdef ANSELA HasANSEL = 1 SetReg ANSELA, 0 endif ifdef ANSELB HasANSEL = 1 SetReg ANSELB, 0 endif ifdef ANSELC HasANSEL = 1 SetReg ANSELC, 0 endif ifdef ANSELD HasANSEL = 1 SetReg ANSELD, 0 endif ifdef ANSELE HasANSEL = 1 SetReg ANSELE, 0 endif ifdef ANSELF HasANSEL = 1 SetReg ANSELF, 0 endif ifdef ANSELG HasANSEL = 1 SetReg ANSELG, 0 endif ifdef ANSELH HasANSEL = 1 SetReg ANSELH, 0 endif ifdef ANSELI HasANSEL = 1 SetReg ANSELI, 0 endif ifdef ANSELJ HasANSEL = 1 SetReg ANSELJ, 0 endif ifdef ANSELK HasANSEL = 1 SetReg ANSELK, 0 endif if (HasANSEL == 0) ifdef ANCON0 ; Several chips use ANCON0 and ANCON1 ifdef ADSHR ; if chip has shared address SFR's MOVE?CT 1, WDTCON,ADSHR ; switch to shared address registers if (SHOWDIGITALRESULT == 1) messg WDTCON.4 = 1 endif endif SetReg ANCON0, 0xFF ; ifdef PCFG15 ; 0 = Analog with these bits SetReg ANCON1, 0xFF else SetReg ANCON1, 0x7F endif ifdef ADSHR ; if chip has shared address SFR's MOVE?CT 0, WDTCON,ADSHR ; put SFR's back to legacy if (SHOWDIGITALRESULT == 1) messg WDTCON.4 = 0 endif endif else ifdef PCFG6 ; Some chips use ADCON1 bits SetReg ADCON1, 0x7F ; the same way as ANCONx else ifdef PCFG3 ; if there's a PCFG3 bit ifdef ADCON2 ; but has no ADCON2, more than 8 A/D's SetReg ADCON1, 0x0F ; A/D cfg from table = 0x0F else SetReg ADCON1, 7 ; most common, 8 or less A/D ch's endif else ifdef PCFG2 ifdef ADCON1 SetReg ADCON1, 7 ; A/D is 8-bit, 5 ch's endif else ifdef ADCON0 ; if there's an ADCON0 ifndef ADCON1 ; but not an ADCON1 SetReg ADCON0, 0 ; A/D is 8-bit and ADS bits are in ADCON0 endif endif endif endif endif endif endif ;----[Comparators]---------------------------------------------------------- ifdef CMCON ifdef CMEN0 ; 18F1230/1330 ;SetReg CMCON, 0 ; default already else ifdef CM2 SetReg CMCON, 7 else ifdef PM_USED "ALLDIGITAL: CMCON value not found" else messg "ALLDIGITAL: CMCON value not found" endif endif endif endif ifdef CMCON0 ifdef NOT_COUTEN SetReg CMCON0, 0xF1 ; 10F204/206 else ifdef CMCH SetReg CMCON0, 0 ; 12F609/615 else ifdef CM2 SetReg CMCON0, 7 ; 12F635/683, else ; 16F636/639/684/688/913/914/916/917/946 ifndef PM_USED "ALLDIGITAL: CMCON0 value not found" else messg "ALLDIGITAL: CMCON0 value not found" endif endif endif endif endif ifdef CM1CON0 ; individual comparator controls ifdef NOT_C1OUTEN SetReg CM1CON0, 0xF1 ; 12F510/506, 16F526 else ; SetReg CM1CON0, 0 ; these already default to 0 -------------- endif ; 16F882/883/884/886/887/ 610/616 endif ; 16F631/677/685/687/689/690 ; these aren't 0, but default to OFF ; 18F24J11/25J11/26J11/44J11/45J11/46J11 ; 18F24J50/25J50/26J50/44J50/45J50/46J50 ifdef CM2CON0 ifdef NOT_C2OUTEN SetReg CM2CON0, 0xF1 else ; SetReg CM2CON0, 0 ; already default to 0 -----see above- endif endif ; CM1CON ; these aren't 0, but default to OFF ; 18F65J50/66J50/66J55/67J50/66J11/66J16/67J11 ; CM2CON ; 18F85J50/86J50/86J55/87J50/86J11/86J16/87J11 ifndef PM_USED list endif ENDASM