CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

16F877 PCWH

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Stoney64



Joined: 25 May 2005
Posts: 2
Location: Cicero NY

View user's profile Send private message

16F877 PCWH
PostPosted: Wed May 25, 2005 3:19 pm     Reply with quote

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]
Code:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 25, 2005 3:25 pm     Reply with quote

Put it on the next line after the #include for the PIC. Example:
Code:
#include <16F877.h>
#device ADC=10
Stoney64



Joined: 25 May 2005
Posts: 2
Location: Cicero NY

View user's profile Send private message

PostPosted: Wed May 25, 2005 3:35 pm     Reply with quote

Well it's just as I thought it would be something simple!! I could have swarn I tried that.

Thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group