Searching \ for '[PIC]: Code Request - ADC on 16F877' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=adc
Search entire site for: 'Code Request - ADC on 16F877'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Code Request - ADC on 16F877'
2002\12\02@020538 by Peter McNulty

picon face
Hi,

Does anyone have tested and working code for ADC on theP16F877. What i need is the code just to print the value of the ADC from some input, to 10 LEDs. I've got 8 LED's working, but either I'm missing something, or my PIC is bad, as i can't get the last two LSB's. They are permanently on or off, don't change. The code I'm using is below, but if you have any of your own code which does this, it'd be ver y much appreciated.

Thanks
-Peter



Code---------------------------


;Setup
list P=16F877
include "c:\P16F877.inc"
errorlevel -302
__CONFIG _CP_OFF & _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF
;Declarations

CounterA equ 20h  org 0x000
goto  Start
       org     0x004

Interrupt
       retfie

Bank1 Macro   ;bank switching macros
bsf STATUS,RP0
bcf STATUS,RP1
bcf STATUS,IRP
Endm

Bank0 Macro
bcf STATUS,RP0
bcf STATUS,RP1
bcf STATUS,IRP
Endm
Init Bank1  movlw b'00000000' ;all of portb are output
movwf TRISB
movlw b'00000001'
movwf TRISA
movlw b'00000000'
movwf TRISD
movlw b'00001110' ;Right justified, channel RA0 is input to ADC
movwf ADCON1

Bank0 ;bank 0
movlw b'00000000' ;all portb low
movwf PORTB
movlw b'00000000'
movwf PORTD
movlw b'10000001' ;RA0 Chn,ADC On,Fosc32
movwf ADCON0
return

ADCStart call Delay
bsf ADCON0,GO
btfsc   ADCON0,GO       ;Wait for conversion to complete
Goto$-1
movf ADRESH,w
movwf PORTB
movf ADRESL,w
movwf PORTD     goto ADCStart
return

;PIC Time Delay = 0.0000280 s with Osc = 20.000000 MHz
Delay movlw D'45'
movwf CounterA

Loop decfsz CounterA,1
goto Loop
return

Start call Init

Main call ADCStart
goto Main
End

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\12\02@025516 by Jinx

face picon face
> movf ADRESH,w
> movwf PORTB
> movf ADRESL,w
> movwf PORTD

ADRESL is in bank1

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\12\02@033131 by Mike Singer

picon face
Peter McNulty wrote:
> Does anyone have tested and working code for ADC on theP16F877. What i
> need is the code just to print the value of the ADC from some input,
to 10
> LEDs. I've got 8 LED's working, but either I'm missing something, or
my PIC is
> bad, as i can't get the last two LSB's. They are permanently on or
off, don't
> change. The code I'm using is below, but if you have any of your own
code
> which does this, it'd be ver y much appreciated.

> Subject: Re-All: [OT]: Temperature Sensors?
> Thanks for the recommendations everyone. It looks like
> I'll take the RTD route as they are fairly linear, cheap,
> fast reponse time ...

  If you have money for RTD, maybe it would be better to spend them on PIC18FXXXX ? If you have to learn
PICs, learn real :-) ones not garbage.    Did you wrote yesterday: "This is a school project" ?

  Mike.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\12\02@080847 by Olin Lathrop

face picon face
> Does anyone have tested and working code for ADC on theP16F877.

http://www.embedinc.com/pic/hal.htm.

For a more in depth reply stop using quoted printable encoding.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\12\02@144651 by Steve Smith

flavicon
face
;------------------------- READ IN ANALOGUE SIGNALS ROUTINE
-------------------
; THIS ROUTINE READS IN THE  ANALOGUE VOLTAGES,

Read_analouge                   ; ENTER WITH CHANNEL NUMBBER 0-4 IN W
       CLRC                    ; CLEAR CARRY BEFORE COMMENCING
       ANDLW   B'00000111'     ; ENSURE NO ERRORS
       MOVWF   GP1             ; TEMP STORE
       RLF     GP1,F
       RLF     GP1,F
       RLF     GP1,W           ; SPIN TO PUT THE CHANELS IN THE RIGHT
PLACE
       ADDLW   B'11000001'     ; SET ADCON0 TO CONVERSION TIME 0F RC
2-6us
       Gie_off                 ; disable int's
       MOVWF   ADCON0          ; DO IT
       BCF     PIR1,ADIF       ; clear intrupt flag
       MOVLW   .23             ; 69 us wait for channel sel to register
       CALL    SHORT           ; SETTLING DELAY FOR A/D
       BSF     ADCON0,2        ; START THE CONVERSION
       btfsc   ADCON0,2        ; test for finished
       goto    $-1             ; no then retest
       Gie_on                  ; enable int's
       RETLW   0               ; EXIT



Try this it works enter with rreqd channel in w exit with result in
adres h,l




{Original Message removed}

2002\12\02@154040 by Olin Lathrop

face picon face
{Quote hidden}

Why do you need to disable interrupts around the acquisition and
conversion?  A longer acquisition time does no harm, and the converted
value stays around after a conversion until you start another one.
Generally I don't like doing "long" things with interrupts disabled.

This routine requires the direct register bank to be set to 0, although
there is no mention of that requirement.  A better strategy is probably to
allow any bank on entry and set it as required.

As an aside, I've found it useful to read the A/D often based on an
interrupt.  There can be a separate interrupt for starting a conversion
and getting the result.  I usually switch to the next channel as soon as
the conversion for the previous channel is complete.  This background A/D
reading code can perform a little optional filtering on the values, then
update a software value that is always kept live.  When the foreground
code needs the current A/D value, it just reads it immediately from the
live software value.  Note that interrupts must be disabled around this
read if it is more than one byte in size.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2002\12\02@170339 by Tony Nixon

flavicon
picon face
> Does anyone have tested and working code for ADC on theP16F877.

Here is a snippet from my analog LCD tutorial that may help.


http://www.bubblesoftonline.com/analog.pdf

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
salesspamspam_OUTbubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\12\02@171856 by Stef

flavicon
face
hi Tony,

Very nice tutorial (as all your products) !
But I now see it for the second time in the past week and I really don't
understand it:
 why  use 8 databits for the LCD, where (in my opinion) you get the
same performance with just 4 databits ?

best regards,
Stef Mientki

Tony Nixon wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


2002\12\02@173602 by Tony Nixon

flavicon
picon face
Stef wrote:
>
> hi Tony,
>
> Very nice tutorial (as all your products) !
> But I now see it for the second time in the past week and I really don't
> understand it:
>   why  use 8 databits for the LCD, where (in my opinion) you get the
> same performance with just 4 databits ?

I also have a 4 bit tutorial later on, but I think 8 bits is easier to
digest especially if trying to get a grasp on other PIC functions and
code at the same time.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
TakeThisOuTsalesEraseMEspamspam_OUTbubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


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