View previous topic :: View next topic |
Author |
Message |
manley
Joined: 08 Feb 2010 Posts: 4
|
problem using multiple files |
Posted: Sun Apr 11, 2010 5:11 pm |
|
|
Hi all.
I am trying to write a program using my picdem2 board, using the onboard lcd as an output for feedback. I want to use "Main.c" and #include "lcd.c" to drive my lcd, with "lcd.c" added to the "Other Files" folder as suggested in the forums.
If I write the Main procedure after the end of "lcd.c" and just use one source file it works fine.
If I remove the main program procedure and use it as "Main.c", the main source file, with #include "lcd.c" in the listing, and add "lcd.c" to the 'Other Files' folder, it doesn't work.
I have followed the recommendations I have found on here and in the CCS manual but I still cannot compile more than one source file. I don't know what I'm doing wrong.
I am using MPLab ver 8.10 with the picdem2plus board and a 16f877a MCU and my compiler is ver 4.099
Please help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 11, 2010 6:20 pm |
|
|
Post a very short program that shows the problem. |
|
|
manley
Joined: 08 Feb 2010 Posts: 4
|
|
Posted: Sun Apr 11, 2010 10:23 pm |
|
|
If this short procedure is added to the flex_lcd driver source file it compiles and works fine. If I separate them and make this file the main file and add the lcd driver to "Other Files" and #include it, it won't compile.
Code: |
#include lcd.c
void main()
{
lcd_init();
delay_ms(6);
printf(lcd_putc,"Hello World");
printf(lcd_putc,"\nline 2");
while(TRUE);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 11, 2010 11:34 pm |
|
|
You need to add the three lines shown in bold, and you need to put
quotes around the lcd.c file.
Quote: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#include "lcd.c"
void main()
{
lcd_init();
delay_ms(6);
printf(lcd_putc,"Hello World");
printf(lcd_putc,"\nline 2");
while(TRUE);
}
|
Is the lcd.c file the Flex lcd driver ? If so, you shouldn't give it the
same name as the CCS lcd driver (which is lcd.c). You should name
it flex_lcd.c.
What's the name of the main file that holds all the code shown above ?
Is it main.c ? If so, you should only have one file in the "Source Files"
list in the MPLAB. It should be main.c. |
|
|
manley
Joined: 08 Feb 2010 Posts: 4
|
thank you.. |
Posted: Wed Apr 14, 2010 8:25 pm |
|
|
Thanks for your help. I appreciate it greatly. This is the first opportunity I have had to log back in so I have still to implement your suggestions. Please don't interpret the delay as lack of interest. Main.c it is.
I am also using the flex_lcd driver and I will rename that also. I am assuming all other source files will be added to the "Other Files"folder.
Thanks again
Manley. |
|
|
|