Searching \ for '[PIC]: Gotcha - A2D pins' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Gotcha - A2D pins'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Gotcha - A2D pins'
2000\08\29@181418 by Tony Nixon

picon face
Hi all,

This may be a gotcha for the unwary - well, it got me anyway.

I thought setting A2D pins as outputs, like RA0 etc, would override the
A2D function of the pins, but this does not seem to be the case on the F

I couldn't figure out why these instructions were not toggling bit 0
when I was testing some software on a 16F873 that I knew had worked
previouly on a 16C74.

  movlw 01h
  xorwf PORTA     <<  PORTA always = 1

After my hair turned a lighter shade of grey, it turned out to be the
ADCON1 setting.

Example: [16F873] ADCON1 = default = A2D pins enabled

set TRISA = 00h
set PORTA = FFh

read PORTA = 00h

I would have thought 2Fh, but not so.
However, it does work on a C74 that I have.

Example: [16F873] ADCON1 = 07h = all digital IO

set TRISA = 00h
set PORTA = 02h

read PORTA = 02h

As expected on both chips.

This may be a trap for Read/Modify/Write type instructions as it will
read all 0's and write them back to the port along with the modified

I suppose the bummer is when you have mixed A2D and digital pins set,
and because of the limited A2D configurations from ADCON1, that you must
have some analog pins set as digital outputs.

Best regards



-- hint: To leave the PICList>

2000\08\29@222736 by Plunkett, Dennis

Yes this is correct! Also note that if you want ADC1 as an analogue port and
ADC0 as a digital this is not possible at the same time unless you turn off
the analogue stuff (PIC16C7710 and 12xxxx)


> {Original Message removed}

2000\08\30@094517 by Barry King

Tony and Dennis pointed out:

> Also note that if you want ADC1 as an analogue port and
> ADC0 as a digital this is not possible

> at the same time

But you can change ADCON and TRIS on the fly to switch pin functions.
For example, switch the port to all digitals, do some digital in
function, then switch on analogs to do an A/D reading.  Sometimes
that lets you use the pins as desired.

Its still a messy proposition- You have to be careful that you don't
leave a mid-range analog input voltage applied to a pin which is then
switched to digital input mode.  If you do, the input buffer will use
excess power becuase its held in the transition region.  When I tried
this, I made it work because I could be sure the analog input circuit
was powered down (and therefore a valid digital zero) when I switched

Barry King, KA1NLH
NRG Systems "Measuring the Wind's Energy"
Check out the accumulated (PIC) wisdom of the ages at:

-- hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's

2000\08\30@094730 by John

Hello Tony & PIC.ers,

I fell foul of this too, I suspect everyone who has migrated
legacy 16c74 code to the 16f8xx parts has had the chance to
curse it.

Such folks might benefit from my own source-code fixup which allows me to
assemble for either 16c74, or the 16f877 which I'm using in this app. for
the ICD debugging capabilities.

Please excuse the lack of tab discipline <blame M$ outhouse>
in the following snippits:-

;******************************************assembler directives begin

#define pic16f877     ;choose  pic16c74 OR pic16f877, should be once only
                                       ;for whole file
      ifdef pic16c74
 #include <>      ;for 16c74 only
         list p=16c74b, r=dec
 #include <>      ;for 16f877 only
         list p=16f877, r=dec
     __config _CP_OFF &_PWRTE_ON &_XT_OSC &_WDT_ON ;normally used with
     errorlevel 1,-302 ;kill off page rp0 warnings
     errorlevel 1,-217

;******************************************assembler directives end


;setup trisa, b, c, d, e
       bsf status,rp0
ifdef pic16c74
 movlf 11111111b, adcon1 ;16c74 setup adcon1 so that porta works digitally,
not analogly - 16c74 style
 movlf 11110111b, adcon1 ;16f877 only, setup adcon1 for 16f877 . NB NOT
like 16c74!!
 movlf 00100000b, trisa
 movlf 11111101b, trisb

etc., etc.,  blah^2

{Quote hidden}

best regards,   John

e-mail from the desk of John Sanderson, JS Controls.
Snailmail:          PO Box 1887, Boksburg 1460, Rep. of South Africa.
Tel/fax:            Johannesburg  893 4154
Cellphone no:   082 469 0446
Manufacturer & purveyor of laboratory force testing apparatus, and related
products and services.

-- hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...