View previous topic :: View next topic |
Author |
Message |
sunny
Joined: 13 Feb 2009 Posts: 3
|
newbies in C language |
Posted: Fri Feb 27, 2009 9:15 pm |
|
|
hi everyone...
i am really new in this stuff..i need to compare two set of voltage using pic 16f877A..how do i achieve this... |
|
|
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
|
Posted: Fri Feb 27, 2009 9:45 pm |
|
|
you will need to start looking at ADC samples, whats the voltage range that you have? |
|
|
sunny
Joined: 13 Feb 2009 Posts: 3
|
|
Posted: Fri Feb 27, 2009 10:15 pm |
|
|
my voltage range is between 5V to 25V..thanks..i should try... |
|
|
sunny
Joined: 13 Feb 2009 Posts: 3
|
|
Posted: Tue Mar 03, 2009 2:14 am |
|
|
This is my code. How can I refer to reference voltage and compare it with input voltage ? Does it have special code or something ?
Code: |
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
#define LED pin_A5
void main() {
int ref,voltage;
setup_port_a( RA0_RA1_ANALOG_RA3_REF );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
ref=5;
while(true){
voltage=read_adc();
if(voltage>ref){
output_high(LED);
}
} |
|
|
|
|