Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC please

Status
Not open for further replies.

ryanese

New Member
Hey, can anyone help me in in Using ADC for PIC16f877. please

can u give me a sample program where two input analog signals are converted to digital and is assigned to 2 different long int values.

in C language please.

thanks so much.

P.S. if ever any of u need help in using a single 16f877 microcontroller for controlling up to 33 servos in C language. ill be glad to help
 
Which C? HiTech and CCS handle the registers quite differently.
 
Here is a short CCS implementation. This program outputs 8 MSB

#include <16f877.h>

#fuses HS,NOWDT,NOPROTECT
#device PIC 16F877 ADC=8
#use delay(clock=20000000)
#use rs232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7)
#opt 9

// Reserve top 255 bytes of memory for the bootloader
#ORG 0x1F00,0x1FFFF{}


void reset()
{
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(1); //Read Pin A1 analog only
delay_us(10);
}

main()
{
int valueADC; //the '#device' directive sets adc to 8 bits

reset();
//printf("Ready");
while(true)
{
valueADC=read_adc();
}
}
 
Oops, I just noticed that you said 2 analog signals....
That's no problem, cause all you have to do is create a function that will change set_adc_channel(1); to set_adc_channel(0); and then read adc value into a second variable.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top