$ifndef __ADC_INC $define __ADC_INC (* ADC libraries for 18F devices The defines and macros are based upon routines included with the Microchip C18 compiler. For 18F devices using version 3.4.0.6 onwards of the Proton+ Compiler *) $if (_core <> 16) $error Must be an 18F Device For the ADC library macros $endif $Include ADCdefs.Inc $if _defined(ADC_V1) $define OpenADC(pC,pC2) _OpenADC pC, pC2 _OpenADC Macro- pConfig, pConfig2 #if(Prm_Count != 2) #error "OpenADC must have 2 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR pConfig,ADCON1 Num_SFR (((pConfig << 2) & 0xC0) | (pConfig2 & 0x38)),ADCON0 ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V2) $define OpenADC(pC,pC2) _OpenADC pC, pC2 _OpenADC Macro- pConfig, pConfig2 #if(Prm_Count != 2) #error "OpenADC must have 2 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR ((pConfig2 >> 1) & 0x3C),ADCON0 Num_SFR (((pConfig2 << 4) & 0x30) | (pConfig & 0b00001111)),ADCON1 Num_SFR ((pConfig & 128) | ((pConfig >> 4) & 0x07)),ADCON2 ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V3) $define OpenADC(pC,pC2,pPC) _OpenADC pC, pC2, pPC _OpenADC Macro- pConfig, pConfig2, pPortConfig #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR (((pConfig2 >> 1) & 0x3C) | ((pConfig2 << 6) & 0xC0)),ADCON0 Num_SFR pPortConfig,ADCON1 Num_SFR (((pConfig & 128)|((pConfig >> 4) & 0x07)) | ((pConfig << 2) & 0x38)),ADCON2 ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V4) Or _defined(ADC_V5) Or _defined(ADC_V6) $define OpenADC(pC,pC2,pPC) _OpenADC pC, pC2, pPC _OpenADC Macro- pConfig, pConfig2, pPortConfig #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR ((pConfig2 >> 1) & 0x3C),ADCON0 Num_SFR (pPortConfig | ((pConfig2 << 4) & 0x30)),ADCON1 Num_SFR ((pConfig & 128) | ((pConfig >> 4) & 0x07) | ((pConfig << 2) & 0x38)),ADCON2 ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V8) $define OpenADC(pC,pC2,pPC) _OpenADC pC, pC2, pPC _OpenADC Macro- pConfig, pConfig2, pPortConfig #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR ((pConfig2 >> 1) & 0x3C),ADCON0 Num_SFR ((pConfig2 << 4) & 0x30),ADCON1 Num_SFR (pConfig & 128 | ((pConfig >> 4) & 0x07) | ((pConfig << 2) & 0x38)),ADCON2 Num_SFR pPortConfig,ANSEL Num_SFR (pPortConfig >> 8),ANSELH ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V7) $define OpenADC(pC1,pC2,pC3) _OpenADC pC1, pC2, pC3 _OpenADC Macro- pConfig1,pConfig2, pConfig3 #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif ANSEL0 = 0 ANSEL1 = 0 ADCHS = 0 Num_SFR ((pConfig1 << 2) & 0x3C),ADCON0 Num_SFR (pConfig2 & 0xC0) | ((pConfig2 >> 1) & 0x10),ADCON1 Num_SFR pConfig3,ADCON2 Num_SFR (pConfig2 & 0x1F) | (pConfig1 & 0xC0),ADCON3 ADCON0bits_ADON = 1 ' Enable the A/D module Endm $elseif _defined(ADC_V7_1) $define OpenADC(pC1,pC2,pC3) _OpenADC pC1, pC2, pC3 _OpenADC Macro- pConfig1, pConfig2, pConfig3 #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif ANSEL0 = 0 ADCHS = 0 Num_SFR ((pConfig1 << 2) & 0x3C),ADCON0 Num_SFR ((pConfig2 & 0xC0) | ((pConfig2 >> 1) & 0x10)),ADCON1 Num_SFR pConfig3,ADCON2 Num_SFR ((pConfig2 & 0x1F) | (pConfig1 & 0xC0)),ADCON3 ADCON0bits_ADON = 1 ' Enable the A/D module Endm $elseif _defined(ADC_V9) $define OpenADC(pC,pC2,pPC) _OpenADC pC, pC2, pPC _OpenADC Macro- pConfig, pConfig2, pPortConfig #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif WDTCONbits_DEVCFG = 0 Num_SFR ((pConfig2 >> 1) & 0x3C) | ((pConfig2 << 6) & 0xC0),ADCON0 Num_SFR (pConfig & 128) | ((pConfig >> 4) & 0x07) | ((pConfig << 2) & 0x38),ADCON1 WDTCONbits_DEVCFG = 1 Num_SFR pPortConfig,ANCON0 Num_SFR (pPortConfig >> 8),ANCON1 WDTCONbits_DEVCFG = 0 ADCON0bits_ADON = 1 Endm $elseif _defined(ADC_V10) $define OpenADC(pC,pC2,pC3,pPC) _OpenADC pC, pC2, pC3, pPC _OpenADC Macro- pConfig, pConfig2, pConfig3, pPortConfig #if(Prm_Count != 4) #error "OpenADC must have 4 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_4 != Num8) && (Prm_4 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR ((pConfig2 >> 1) & 0x3C),ADCON0 Num_SFR ((pConfig3 & 0x0C) | (pConfig3 & 0x03)),ADCON1 Num_SFR ((pConfig & 128) | ((pConfig >> 4) & 0x07) | ((pConfig << 2) & 0x38)),ADCON2 Num_SFR pPortConfig,ANSEL Num_SFR (pPortConfig >> 8),ANSELH ADCON0bits_ADON = 1 'A/D Conversion Status bit--A/D converter module is operating Endm $elseif _defined(ADC_V11) $define OpenADC(pC,pC2,pC3) _OpenADC pC, pC2, pC3 _OpenADC Macro- pConfig, pConfig2, pConfig3 #if(Prm_Count != 3) #error "OpenADC must have 3 Parameters for this device" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_2 != Num8) && (Prm_2 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif #if((Prm_3 != Num8) && (Prm_3 != Num16)) #error "OpenADC Parameters must be constant values" Exitm #endif Num_SFR (((pConfig2 >> 1) & 0x3C) | ((pConfig2 << 6) & 0xC0)),ADCON0 Num_SFR ((pConfig & 128) | ((pConfig >> 4) & 0x07) | ((pConfig << 2) & 0x38)),ADCON1 Num_SFR (pConfig3 >> 8),ANCON0 ' VBG Selection and port pConfiguration Num_SFR pConfig3,ANCON1 ' port pConfiguration ADCON0bits_ADON = 1 Endm $endif '------------------------------------------------------------------------- ' *** ADC Interrupt Enable Macros *** '------------------------------------------------------------------------- $if _defined(ADC_V1) Or _defined(ADC_V2) Or _defined(ADC_V3) Or ' _defined(ADC_V4) Or _defined(ADC_V5) Or _defined(ADC_V8) Or ' _defined(ADC_V6) Or _defined(ADC_V7) Or _defined(ADC_V7_1) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define ADC_IntEnable() PIR1bits_ADIF = 0 : PIE1bits_ADIE = 1 : INTCONbits_PEIE = 1 $elseif _defined(ADC_V9) $define ADC_IntEnable() WDTCONbits_DEVCFG = 0 : PIR1bits_ADIF = 0 : PIE1bits_ADIE = 1 : INTCONbits_PEIE = 1 $endif '------------------------------------------------------------------------- ' *** ADC Interrupt Disable Macros *** '------------------------------------------------------------------------- $if _defined(ADC_V1) Or _defined(ADC_V2) Or _defined(ADC_V3) Or ' _defined(ADC_V4) Or _defined(ADC_V5) Or _defined(ADC_V8) Or ' _defined(ADC_V6) Or _defined(ADC_V7) Or _defined(ADC_V7_1) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define ADC_IntDisable() PIE1bits_ADIE = 0 : INTCONbits_PEIE = 0 $elseif _defined(ADC_V9) $define ADC_IntDisable() WDTCONbits_DEVCFG = 0 : PIE1bits_ADIE = 0 : INTCONbits_PEIE = 0 $endif '------------------------------------------------------------------------- ' *** CloseADC Macros *** '------------------------------------------------------------------------- $if _defined(ADC_V1) Or _defined(ADC_V2) Or _defined(ADC_V3) Or ' _defined(ADC_V4) Or _defined(ADC_V5) Or _defined(ADC_V8) Or ' _defined(ADC_V6) Or _defined(ADC_V7) Or _defined(ADC_V7_1) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define CloseADC() ADCON0bits_ADON = 0 : PIE1bits_ADIE = 0 $elseif _defined(ADC_V9) $define CloseADC() WDTCONbits_DEVCFG = 0 : ADCON0bits_ADON = 0 : PIE1bits_ADIE = 0 $endif '------------------------------------------------------------------------- ' *** SelChanConvADC Macros *** '------------------------------------------------------------------------- $if _defined(ADC_V1) $define SelChanConvADC(pCH) _SelChanConvADC pCH _SelChanConvADC Macro- pChannel #if(Prm_Count != 1) #error "SelChanConvADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SelChanConvADC Parameter must be constant value" Exitm #endif movlw 0xC3 andwf ADCON0,W iorlw (pChannel & 0x38) movwf ADCON0 ADCON0bits_GO_DONE = 1 Endm $elseif _defined(ADC_V2) Or _defined(ADC_V3) Or _defined(ADC_V4) Or ' _defined(ADC_V5) Or _defined(ADC_V6) Or _defined(ADC_V8) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define SelChanConvADC(pCH) _SelChanConvADC pCH _SelChanConvADC Macro- pChannel #if(Prm_Count != 1) #error "SelChanConvADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SelChanConvADC Parameter must be constant value" Exitm #endif movlw 0xC3 andwf ADCON0,W iorlw ((pChannel >> 1) & 0x3C) movwf ADCON0 ADCON0bits_GO_DONE = 1 Endm $elseif _defined(ADC_V9) $define SelChanConvADC(pCH) _SelChanConvADC pCH _SelChanConvADC Macro- pChannel #if(Prm_Count != 1) #error "SelChanConvADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SelChanConvADC Parameter must be constant value" Exitm #endif WDTCONbits_DEVCFG = 0 movlw 0xC3 andwf ADCON0,W iorlw ((pChannel >> 1) & 0x3C) movwf ADCON0 ADCON0bits_GO_DONE = 1 Endm $elseif _defined(ADC_V7) $define SelChanConvADC(pCH) _SelChanConvADC pCH _SelChanConvADC Macro- pChannel #if(Prm_Count != 1) #error "SelChanConvADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SelChanConvADC Parameter must be constant value" Exitm #endif #if(pChannel != 8) Num_SFR (1 << pChannel),ANSEL0 #else Num_SFR 1,ANSEL1 #if(pChannel == 0) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFC #endif #if(pChannel == 1) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11001111 #endif #if(pChannel == 2) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110011 #endif #if(pChannel == 3) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %00111111 #endif #if(pChannel == 4) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFD #endif #if(pChannel == 5) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11011111 #endif #if(pChannel == 6) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110111 #endif #if(pChannel == 7) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %01111111 #endif #if(pChannel == 8) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFE #endif #endif ADCON0bits_GO_DONE = 1 Endm $elseif _defined(ADC_V7_1) $define SelChanConvADC(pCH) _SelChanConvADC pCH _SelChanConvADC Macro- pChannel #if(Prm_Count != 1) #error "SelChanConvADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SelChanConvADC Parameter must be constant value" Exitm #endif Num_SFR (1 << pChannel),ANSEL0 #if(pChannel == 0) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFC #endif #if(pChannel == 1) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11001111 #endif #if(pChannel == 2) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110011 #endif #if(pChannel == 3) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %00111111 #endif #if(pChannel == 4) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFD #endif ADCON0bits_GO_DONE = 1 Endm $endif '------------------------------------------------------------------------- ' *** SetChanADC Macros *** '------------------------------------------------------------------------- $if _defined(ADC_V1) $define SetChanADC(pCH) _SetChanADC pCH _SetChanADC Macro- pChannel #if(Prm_Count != 1) #error "SetChanADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SetChanADC Parameter must be constant value" Exitm #endif Num_SFR ((pChannel >> 1) & 0x3C),ADCON0 movlw 0xC7 andwf ADCON0,W iorwf ADCON0,F Endm $elseif _defined(ADC_V2) Or _defined(ADC_V3) Or _defined(ADC_V4) Or ' _defined(ADC_V5) Or _defined(ADC_V6) Or _defined(ADC_V8) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define SetChanADC(pCH) _SetChanADC pCH _SetChanADC Macro- pChannel #if(Prm_Count != 1) #error "SetChanADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SetChanADC Parameter must be constant value" Exitm #endif Num_SFR ((pChannel >> 1) & 0x3C),ADCON0 movlw 0xC3 andwf ADCON0,W iorwf ADCON0,F Endm $elseif _defined(ADC_V9) $define SetChanADC(pCH) _SetChanADC pCH _SetChanADC Macro- pChannel #if(Prm_Count != 1) #error "SetChanADC must have 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "SetChanADC Parameter must be constant value" Exitm #endif WDTCONbits_DEVCFG = 0 Num_SFR ((pChannel >> 1) & 0x3C),ADCON0 movlw 0xC3 andwf ADCON0,W iorwf ADCON0,F Endm $endif $if _defined(ADC_V1) Or _defined(ADC_V2) Or _defined(ADC_V3) Or ' _defined(ADC_V4) Or _defined(ADC_V5) Or _defined(ADC_V6) Or ' _defined(ADC_V7) Or _defined(ADC_V7_1) Or _defined(ADC_V8) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define BusyADC() _BusyADC _BusyADC Macro- \ Byte #if(BusyADC_Return == 1) #if(Return_Type == Byte) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_byte Return_Var #endif #if(Return_Type == Word) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_word Return_Var #endif #if(Return_Type == Dword) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_dword Return_Var #endif #if(Return_Type == Bit) #error "BusyADC Macro cannot return a bit variable" #endif #endif Endm $elseif _defined(ADC_V9) $define BusyADC() _BusyADC _BusyADC Macro- \ Byte WDTCONbits_DEVCFG = 0 #if(BusyADC_Return == 1) #if(Return_Type == Byte) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_byte Return_Var #endif #if(Return_Type == Word) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_word Return_Var #endif #if(Return_Type == Dword) movlw 0 btfsc ADCON0bits_GO_DONE movlw 1 wreg_dword Return_Var #endif #if(Return_Type == Bit) #error "BusyADC Macro cannot return a bit variable" #endif #endif Endm $endif $if _defined(ADC_V1) $define ReadADC(pCH) _ReadADC pCH _ReadADC Macro- pChannel \ Word #if(Prm_Count == 0) ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Exitm #endif #if(Prm_Count > 1) #error "ReadADC must have only 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16) && (Prm_1 != Num32)) #error "ReadADC Parameter must be constant value" Exitm #endif movlw 0xC3 andwf ADCON0,W iorlw (pChannel & 0x38) movwf ADCON0 ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Endm $elseif _defined(ADC_V2) Or _defined(ADC_V3) Or _defined(ADC_V4) Or ' _defined(ADC_V5) Or _defined(ADC_V6) Or _defined(ADC_V8) Or ' _defined(ADC_V10) Or _defined(ADC_V11) $define ReadADC(pCH) _ReadADC pCH _ReadADC Macro- pChannel \ Word #if(Prm_Count == 0) ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Exitm #endif #if(Prm_Count > 1) #error "ReadADC must have only 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "ReadADC Parameter must be constant value" Exitm #endif movlw 0xC3 andwf ADCON0,W iorlw ((pChannel >> 1) & 0x3C) movwf ADCON0 ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Endm $elseif _defined(ADC_V9) $define ReadADC(pCH) _ReadADC pCH _ReadADC Macro- pChannel \ Word #if(Prm_Count == 0) WDTCONbits_DEVCFG = 0 ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Exitm #endif #if(Prm_Count > 1) #error "ReadADC must have only 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "ReadADC Parameter must be constant value" Exitm #endif WDTCONbits_DEVCFG = 0 movlw 0xC3 andwf ADCON0,W iorlw ((pChannel >> 1) & 0x3C) movwf ADCON0 ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Endm $elseif _defined(ADC_V7) $define ReadADC(pCH) _ReadADC pCH _ReadADC Macro- pChannel \ Word #if(Prm_Count == 0) ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Exitm #endif #if(Prm_Count > 1) #error "ReadADC must have only 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "ReadADC Parameter must be constant value" Exitm #endif #if(pChannel != 8) Num_SFR (1 << pChannel),ANSEL0 #else Num_SFR 1,ANSEL1 #if(pChannel == 0) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFC #endif #if(pChannel == 1) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11001111 #endif #if(pChannel == 2) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110011 #endif #if(pChannel == 3) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %00111111 #endif #if(pChannel == 4) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFD #endif #if(pChannel == 5) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11011111 #endif #if(pChannel == 6) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110111 #endif #if(pChannel == 7) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %01111111 #endif #if(pChannel == 8) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFE #endif #endif ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Endm $elseif _defined(ADC_V7_1) $define ReadADC(pCH) _ReadADC pCH _ReadADC Macro- pChannel \ Word #if(Prm_Count == 0) ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Exitm #endif #if(Prm_Count > 1) #error "ReadADC must have only 1 Parameter" Exitm #endif #if((Prm_1 != Num8) && (Prm_1 != Num16)) #error "ReadADC Parameter must be constant value" Exitm #endif Num_SFR (1 << pChannel),ANSEL0 #if(pChannel == 0) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFC #endif #if(pChannel == 1) ADCHS = ADCHS | %00110000 ADCHS = ADCHS & %11001111 #endif #if(pChannel == 2) ADCHS = ADCHS | %00001100 ADCHS = ADCHS & %11110011 #endif #if(pChannel == 3) ADCHS = ADCHS | %11000000 ADCHS = ADCHS & %00111111 #endif #if(pChannel == 4) ADCHS = ADCHS | 0x03 ADCHS = ADCHS & 0xFD #endif ADCON0bits_GO_DONE = 1 #ifdef WatchDog_Req clrwdt btfsc ADCON0bits_GO_DONE bra($ - 4) #else btfsc ADCON0bits_GO_DONE bra($ - 2) #endif #if(_ReadADC_Return == 1) #if(Return_Type == Byte) Byte_Byte ADRESH,Return_Var #endif #if(Return_Type == Word) #if(Return_Var != ADRESL) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 #endif #endif #if(Return_Type == Dword) Byte_Byte ADRESL,Return_Var Byte_Byte ADRESH,Return_Var + 1 Num_Word 0,Return_Var + 2 #endif #endif Endm $endif $endif