Jomile
Joined: 06 Nov 2007 Posts: 5
|
ADC-- RA0 has a non-zero voltage on it |
Posted: Wed Nov 07, 2007 3:03 pm |
|
|
I am using the A port for ADC (16F877A). When i use RA1 i have no problem but for some reason I am having issues with RA0. I measured the voltage on the pin and it is 2.14V (open). I tried two chips. Is there something I am missing in code?
Code: |
#include "C:\Program Files\PICC\Projects\11-7-07\main.h"
#include <string.h>
void main()
{
int value;
setup_adc_ports(RA0_RA1_RA3_ANALOG);
//setup_adc_ports(AN0_AN1_AN2_AN4_VSS_VREF);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//SET_TRIS_A( 0xFF );
// B7,B6,B5,B4 are outputs
// B3,B2,B1,B0 are inputs
printf("Start");
set_adc_channel( 0 );
output_high(PIN_C0);
while(TRUE){
output_low(PIN_C0);
spi_write(0x30);
spi_write(0x0F);
output_high(PIN_C0);
output_high(PIN_C1);
delay_ms(500);
value = read_adc();
printf("A/D value = %2x\n\r", value);
delay_ms(2000);
output_low(PIN_C0);
spi_write(0x3F);
spi_write(0x00);
output_high(PIN_C0);
output_low(PIN_C1);
delay_ms(500);
value = read_adc();
printf("A/D value = %2x\n\r", value);
delay_ms(2000);
}
}
.h file
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
|
|