Stoney64
Joined: 25 May 2005 Posts: 2 Location: Cicero NY
|
16F877 PCWH |
Posted: Wed May 25, 2005 3:19 pm |
|
|
Hello,
I am using a PIC 16F877 and trying to use the A2D when I first ran my code I was getting only 8 bit 0-FF then I found the #device ADC=10 when I try to use this I get an Error 23 "Can not change device this far into the code" So what am I doing wrong.
[/code]#include <16F877.h>
#include <STDLIB.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
// Function Prototypes
void convert_to_volts(long int data,char volts[6]);
void display_data(long int data);
void main() {
int i;
long int value, min, max;
printf("Sampling:\r\n");
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
do {
delay_ms(100);
value = Read_ADC();
printf("\n\rCh0: ");
display_data( value );
} while (TRUE);
}
// Function Definitions
void convert_to_volts ( long int data , char volts[6]){
BYTE i;
long int temp,div;
div=0x3330;
for(i=0;i<=4;i++){
temp=data/div;
volts[i]=(BYTE)temp+'0';
if(i==0) {
volts[1]='.';
i++;
}
temp=div*(BYTE)temp;
data=data-temp;
div=div/10;
}
volts[i]='\0';
}
void display_data ( long int data)
{
char volt_string [6];
convert_to_volts(data, volt_string);
printf(volt_string);
printf(" (%41X)",data);
}
I am using version 3.218
Thanks
Stoney[/code] |
|