CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC using ... PIC18f2331

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sonicdeejay



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

ADC using ... PIC18f2331
PostPosted: Tue Dec 20, 2005 1:18 am     Reply with quote

May I know how can I write a analog to digital conveter using PIC18F2331??


PortA 0 will be input for analog in....


and PortB 0 will be digital output for for the digitalised signal from PortA 0.



Thanks in advance...

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 12:29 pm     Reply with quote

Quote:
May I knw how can I write a analog to digital conveter using PIC18F2331??
PortA 0 will be input for anlog in....
PortB 0 will be digital output for for the digitalised signal from port A 0.

Study these functions in the CCS manual and in the example files:

setup_adc_ports()
setup_adc()
read_adc()
set_adc_channel()
output_b()

Download the CCS manual here:
http://www.ccsinfo.com/ccscmanual.zip

The example files are in this folder:
c:\Program Files\PICC\Examples
sonicdeejay



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

PostPosted: Sat Jan 14, 2006 1:30 am     Reply with quote

Guys,,,I can make it works...thanks for help...

Code:

#include<16f877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void main() {
int i, value, min, max;

printf("Sampling:");

setup_adc_ports( RA0_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );

do { //Takes 30 samples from pin A0
min = 255; //and displays the min and max
max = 0; //values for that 100ms period
for(i = 0; i <= 30; ++i) {
delay_ms(100);
value = read_adc();
if(value < min)
min = value;
if(value > max)
max = value;
}
printf("\n\rMin:%x MAX: %x", min, max);
} while (TRUE);
}

The above ADC sample show that it reads "Input" from Port A0, calculates max, min etc and display via RS232....

Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group