### Welcome to EDAboard.com

#### Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

#### faraz101

##### Full Member level 1

i need pic adc examples code and projects.
i want to use pic16f877 for checking 4 analog quantities.
any references?

#### Kurenai_ryu

wich language? compiler?
in ccs...
Code:
#include "16f877.h"
#use delay(clock=4000000)
#use fast_io(B)
void main(void)
{
set_tris_b(0);
while(1)
{
delay_us(20);
}

}

#### faraz101

##### Full Member level 1

thanx friend
please give me the examples in mikro c if u can.
have a nice day

#### blastronics

##### Member level 3

sir,

You can find lots of sample program at PIClist.com
I have used sample programs here as a reference for my ADC programs.

blastronics

#### faraz101

##### Full Member level 1

ok friends i have written the code in mikro c for pic16f877 adc using read adc command.
i connect the pot on adc input and drive led on o/p port.now i want to read analog voltage on serial port.

#### aandavan

pic16f877 example

U might get the output from ADRESL and ADRESH register. You have to move the value from those register to TXREG register. The digital value will be transferred automatically

#### faraz101

##### Full Member level 1

actuallly i have barrometric pressure sensor mpx4115.it has output analog voltge
from 0 to 5v.i want to measure these voltage and display the pressure on the hyper terminal like this.
PRESSURE = 56kPa
how i can do this?

#### Kurenai_ryu

easy! but can you tell us your voltaje-pressure ratio? (maybe I can get an answer next day- my USB-stick just died today...

#### faraz101

##### Full Member level 1
pic16f877 examples

i want to use mpx4115 motorolla sensor to measure altitude of my plane.this is barrometric pressure sensor which o/p the 0.2v to 5v.its pressure range is 2.2 to 16.7 psi.
i want to measure 0.2v to 5v with pic adc and display the altitude on hyper terminal after calculations.

#### faraz101

##### Full Member level 1
usart_write

i have written the code in MIKRO C which is as follows

void main() {
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
usart_init(2400);

do {

volt = press+48.0;
usart_write(86);
usart_write(79);
usart_write(76);
usart_write(84);
usart_write(61);
usart_write(volt);
usart_write(13);
delay_ms(1000);
} while(1);
}

and the result on the hyper terminal are the
VOLT = 1
OR
VOLT = 2 ETC
but the hyper terminal do not shoew the decimal point
for example if i give the i/p of 1.5v at the i/p it still shows the 1v.
and if i give any voltage b/w 2 to 3 volt it shows 2v and on reaching 3v it shows 3v.
what the problem with that.
thanx

#### Kurenai_ryu

its very strange! why do you add 48 (30h)??? of course if you are converting the number to ASCII in some poor way it cant display float numbers! did you think that usart_write can convert numbers to float???
mmmmm
well, i can suggest something like this
Code:
void main() {
char inter, deci;
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
usart_init(2400);

do {

inter = (int) press;
deci= (int) (press*10.0) - inter*10;
usart_write('V');
usart_write('O');
usart_write('L');
usart_write('T');
usart_write('=');
usart_write(inter | 0x30);
usart_write('.');
usart_write(deci | 0x30);
usart_write(13);
usart_write(10);
delay_ms(1000);
} while(1);
}

#### faraz101

##### Full Member level 1

thanx brother
actually i dont know much about c language and mikro c.will u please sugges or give me the manual of mikro c to know about such commands about mikro.
thanx again for the help.
FARAZ

#### spawndevil89

##### Newbie level 1
can someone translate the code to C? thanks!

#### Bilal_Rahim

##### Newbie level 3

guys i m new in micro controllers so i need your help.

i want to use PIC16F877 for my new project please give me some use full tips.
i acquire the audio signal from mic and want to convert in digital form using above mentioned PIC, but i don't know how i do this because i am totally blank about micro controllers but i want to do that project please help me out thanks........

#### Tahmid

Hi Bilal,
The output voltage from the mic is very very low. I think you should first amplify this with an amplifier stage and then send this amplified output to the PIC ADC input to be read.
What compiler are you using?
In mikroBASIC or mikroC there is a command ADC_Read which is very easy.
Code:
'mikroBASIC:
ADR = ADC_Read(0) 'Read from channel 0 and copy digital value to ADR
Code:
'mikroC:
unsigned int word;
ADR = ADC_Read(0);
Hope this helps.
Tahmid.

#### Bilal_Rahim

##### Newbie level 3
which one you suggest to use???
mikroC or mikroBASIC?

#### Tahmid

It depends on your understanding of either C or BASIC language. I personally use mikroBASIC, but if you can use C go for mikroC, if you can use BASIC, go for mikroBASIC.

#### Bilal_Rahim

##### Newbie level 3
ok i'll use mikroC for it thanks for your help.
if i need some help then i will ask you...

#### bogusmeister

##### Junior Member level 2
hi guys. actually im having a related problem.. im using PIC16F877 and i want to convert the analog voltage coming from my analog reflectance sensor. could you give me a sample ADC assembly program for MPLAB IDE that could help me. THANKS

#### vinodstanur

This is available in data sheet..
Then using a C compiler 'like HIGH TECH C' try 2 write a program...
I am sure u could do it....

nagabhargavamrita

points: 2