|
|
View previous topic :: View next topic |
Author |
Message |
dorinjj
Joined: 21 Jan 2011 Posts: 5
|
stdlib.h problem? |
Posted: Fri Jan 21, 2011 7:33 pm |
|
|
Hi, I'm new in c programming of pic mcu's and a new member of this forum, but in the process of c learning, I think that I discovered a problem with the "stdlib.h" library when is used with "#device ADC=10" directive.
I can't compile my code when I try to include "stdlib.h" library for use "itoa()" function when I have "#device ADC=10" directive and the error messages are:
*** Error 23 "led_test.c" Line 3(8,9): Can not change device type this far into the code
*** Error 48 "led_test.c" Line 3(9,12): Expecting a (
*** Error 43 "led_test.c" Line 3(13,15): Expecting a declaration
3 Errors, 0 Warnings.
The device which I use is PIC16F887.
What is the problem? Thank You.
Code: |
#include <16F887.H>
//#include <stdlib.h> // problem!? I can't use this *
#device ADC=10 // ? *
#fuses INTRC_IO, NOMCLR, NOWDT
#use delay(clock=8M)
#use rs232(uart1, baud=9600, parity=N)
void main()
{ setup_oscillator(OSC_8MHZ);
set_tris_d(0x00);
int16 r,var;
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
while(1)
{
r =read_adc();
output_d(r);
printf("AD value is %4LD \r\n", r);
delay_ms(1000);
}
}
|
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri Jan 21, 2011 7:42 pm |
|
|
Swap the second and third lines. The device declarations must always come first _________________ Google and Forum Search are some of your best tools!!!! |
|
|
dorinjj
Joined: 21 Jan 2011 Posts: 5
|
|
Posted: Fri Jan 21, 2011 8:03 pm |
|
|
Thank You for reply.
Problem solved. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sat Jan 22, 2011 3:16 am |
|
|
I'd actually say, to avoid future problems, put the include down after _all_ the initialisation stuff. So:
1) Processor define/include
2) Any extra 'device' statements
3) Fuses and clock statements
4) device configuration (#use RS232/I2C etc.)
5) Include other stuff & defines
6) main code.
Problem is that if any included file uses RS232, or timings, it really needs to come after the clock setups, and RS232 declarations. Think of 1 to 4, as the 'header', that must be there before other code is loaded.
You can twiddle the order a little, _but_ in general, this is the safest layout to use, and is quite logical.
Best Wishes |
|
|
|
|
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
|