View Full Version : ADC with LED output
  
inventor2008
- 9th April 2008, 07:02
hi
    I recently moved from my bs2 to pic's and I have a pic16f877A that I only recently got to work, and I've already gotten it to do most of basic stuff, blink and LED, run an LCD, run a servo, and so on... and today I started messing with the ad converter and just loaded one of the demo adc programs that came with pbp, to see what would happen and I got it to work, but It displays the digital value of portA.0 on the LCD and I was wondering would it be possible to display the value on portA.0 with LED's (say on portD) instead of the LCD so instead of seeing "Value : (and what ever number)" I would see 8 LED's displaying the binary value of portA.0.
Thanks
skimask
- 9th April 2008, 07:58
trisd = 0 'set portd to all outputs
adresult var byte 'set up a byte that will receive the a/d input from the ADC
portd = adresult 'set portd to the result value
T.Jackson
- 9th April 2008, 16:47
Please disregard post.
skimask
- 9th April 2008, 17:18
C:>del t.jackson
Acetronics2
- 9th April 2008, 18:06
Hi, Trent
It would be really very nice from you to stay upon PIC related subjects ...
Hope you understand it told like here ...
Thanks
Alain
T.Jackson
- 9th April 2008, 18:11
Alain,
You've heard the last of it. Cyas later.
lester
- 9th April 2008, 18:35
T Jackson,
Please moderate your responses...before i moderate them for you.
I dont see your post being PIC related, or supportive of  users on the forum.
I have received a complaint about your post. Looking at the post in this thread i can see no good reason for it.
Please take heed, i don't have a lot of time, so my descisions will be swift!
Thank you for your attention.
T.Jackson
- 9th April 2008, 18:51
Sorry about this Lester.
It might be more appropriate if the posts are completely removed. Once again -- sorry for concerning you with this. You've heard the last of it, you have my word.
mister_e
- 9th April 2008, 19:11
hi
    I recently moved from my bs2 to pic's and I have a pic16f877A that I only recently got to work, and I've already gotten it to do most of basic stuff, blink and LED, run an LCD, run a servo, and so on... and today I started messing with the ad converter and just loaded one of the demo adc programs that came with pbp, to see what would happen and I got it to work, but It displays the digital value of portA.0 on the LCD and I was wondering would it be possible to display the value on portA.0 with LED's (say on portD) instead of the LCD so instead of seeing "Value : (and what ever number)" I would see 8 LED's displaying the binary value of portA.0.
Thanks
trisd = 0 'set portd to all outputs
adresult var byte 'set up a byte that will receive the a/d input from the ADC
portd = adresult 'set portd to the result value
Hi inventor2008, 
Skimask gave you nice tips.  Since you're a beginner, i'll give you a working example of it.. just to compensate some "unwanted post" in your thread.
<font color="#000000">        <font color="#008000">'
        '   this assume you use a 20MHz crystal 
        '                    &
        '              PM as assembler
        '
        </font>@    device hs_osc, lvp_off
        <font color="#000080">DEFINE </font>OSC 20
        
        TRISA = 255 <font color="#008000">' PORTA = INPUT
        </font>TRISD = 0   <font color="#008000">' PORTD = OUTPUT
        
        </font><font color="#000080">DEFINE </font>ADC_BITS  8     <font color="#008000">' ADCIN resolution  (Bits)
        </font><font color="#000080">DEFINE </font>ADC_CLOCK 3     <font color="#008000">' ADC clock source  (Frc)
        </font><font color="#000080">DEFINE </font>ADC_SAMPLEUS 50 <font color="#008000">' ADC sampling time (uSec)
        
        </font>ADResult    <font color="#000080">VAR BYTE
        
        </font>PORTD=0 <font color="#008000">' Clear all LEDs on PORTD
        
</font>Start:
        <font color="#000080">ADCIN </font>0,ADResult
        PORTD = ADResult
        <font color="#000080">GOTO </font>Start        
HTH
inventor2008
- 9th April 2008, 19:32
Hi, thanks for answering
    I forgot to to set portD as out, and there was a short in my potentiometer. I defined portD as out and got this...
trisd =0
' Define ADCIN parameters
Define	ADC_BITS	8	
Define	ADC_CLOCK	3	
Define	ADC_SAMPLEUS	50	
adval	var	byte		
	TRISA = %11111111	
	ADCON1 = %00000010	
	Pause 500		
loop:	ADCIN 0, adval
    portd = adval
	 
	Goto loop		
	End
then I got a different pot and It seems to work now.
Thanks!!!
 
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.