![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mle Guest
|
errors in include file |
Posted: Tue Jun 24, 2003 8:00 am |
|
|
Hello,
I'm very new to CCS and I've written a main program which includes an lcd driver that I also wrote. The lcd driver is called mylcd.c and in my main program I have
#include <mylcd.c>
When I try to compile the main program I get errors from the mylcd.c file such as:
"A #device is required before this line"
and if I add that, I get
"No main() function found"
How do I create a file that I can include in other files without making it like a main program?
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515515 |
|
![](templates/subSilver/images/spacer.gif) |
Daniel Brännwik Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 8:09 am |
|
|
:=Hello,
:=I'm very new to CCS and I've written a main program which includes an lcd driver that I also wrote. The lcd driver is called mylcd.c and in my main program I have
:=#include <mylcd.c>
:=
:=When I try to compile the main program I get errors from the mylcd.c file such as:
:="A #device is required before this line"
:=and if I add that, I get
:="No main() function found"
:=
:=How do I create a file that I can include in other files without making it like a main program?
:=
:=mle
Try something like this:
In the main program file:
#device PIC16F877 (or whatever you're using)
#include "mylcd.c"
void main (void)
{
write_lcd();
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515516 |
|
![](templates/subSilver/images/spacer.gif) |
mle Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 8:28 am |
|
|
Thanks, but it I still get the same errors.
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515517 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 8:52 am |
|
|
:=Hello,
:=I'm very new to CCS and I've written a main program which includes an lcd driver that I also wrote. The lcd driver is called mylcd.c and in my main program I have
:=#include <mylcd.c>
:=
:=When I try to compile the main program I get errors from the mylcd.c file such as:
:="A #device is required before this line"
:=and if I add that, I get
:="No main() function found"
:=
:=How do I create a file that I can include in other files without making it like a main program?
:=
:=mle
You are going to have to post some example code. As Daniel has allready said, what you describe should work, provided there is a 'main' function in your primary file, and the device is defined first. Just to make the point, the following is a 'minimum' demo, of using the include
First the 'primary' file:
#include "test16.h"
#include "subs.h"
void main (void)
{
int count;
while (TRUE) {
for (count=1;count<128;count++)
demo_sub(count);
}
}
Now the 'test16.h' file:
//Change to suit the target processor
#include <16F877A.h>
#use delay(clock=20000000)
#fuses HS,NOWDT
Now the 'subs.h' file:
void demo_sub(count) {
output_high (PIN_A0);
delay_ms(count);
output_low (PIN_A0);
delay_ms(count);
}
All this does, is 'toggle' pin A0, ptutting it high, then low, for 1,2,3,4... mSec, to 127msec, then starting again, but it shows how the subroutine can be included in a seperate file.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515521 |
|
![](templates/subSilver/images/spacer.gif) |
mle Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 10:13 am |
|
|
Hello,
This is what i have in the MAIN program:
-------------------------------------------
#include <mylcd.c>
...a bunch of defines
...some functions
/***************Main Program Starts Here*************/
void main(){
/*----------configure all the ports-------*/
Set_Tris_A(0x00); //set port A to outputs
Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
//RB1 (DQin) and RB0(pulse in) inputs
Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
//RC2, RC1, RC0 inputs
Set_Tris_D(0x00); //set port D to outputs
Set_Tris_E(0x00); //set port E to outputs
delay_us(500);
lcd_init();
lcd_clear();
lcd_puts("Hello World");
while(1);
}
------------------------------------------------
And then in the mylcd.c file I have:
#include <16F877.h>
#use delay(clock = 4000000)
#BIT LCD_EN = 0x05.1 //maps the enable bit to RA1
#BIT LCD_RS = 0x05.3 //maps the rs bit to RA3
#BYTE PORTA = 0x05 //PORTA IS ADDRESS 5
#BYTE PORTD = 0x08 //PORTD IS ADDRESS 8
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
...a bunch of functions
----------------------------------------------------
when i try to compile the MAIN file, it gives me an error in the mylcd.c "no main() function found".
Thanks,
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515529 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 10:29 am |
|
|
:=Hello,
:=This is what i have in the MAIN program:
:=
:=-------------------------------------------
:=#include <mylcd.c>
:=
Start here. The '<>' form, implies the file to be included, must be in the 'system' include directory. This is normally where the files like stdio.h reside. You should use the "" form instead for your own files, otherwise they won't allways be found. This is standard code for the include format (I don't think the CCS C makes the distinction, but it could cause problems on other C's). The second thing is that you are trying to 'include', a 'C' file. By default, a 'C' file, will be expected to be a complete program (possibly with it's own includes), and have a main. You should rename the file to be a '.h' file, which is the standard for a partial 'includable' file. This is why the compiler is complaining.
:=...a bunch of defines
:=
:=...some functions
:=
:=/***************Main Program Starts Here*************/
:=void main(){
:=
:=/*----------configure all the ports-------*/
:=Set_Tris_A(0x00); //set port A to outputs
:=Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
:= //RB1 (DQin) and RB0(pulse in) inputs
:=Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
:= //RC2, RC1, RC0 inputs
:=Set_Tris_D(0x00); //set port D to outputs
:=Set_Tris_E(0x00); //set port E to outputs
:=
:=delay_us(500);
:=lcd_init();
:=
:=lcd_clear();
:=lcd_puts("Hello World");
:=
:=
:=while(1);
:=}
:=------------------------------------------------
:=And then in the mylcd.c file I have:
:=
:=#include <16F877.h>
:=#use delay(clock = 4000000)
:=
:=#BIT LCD_EN = 0x05.1 //maps the enable bit to RA1
:=#BIT LCD_RS = 0x05.3 //maps the rs bit to RA3
:=#BYTE PORTA = 0x05 //PORTA IS ADDRESS 5
:=#BYTE PORTD = 0x08 //PORTD IS ADDRESS 8
:=
:=#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
:=#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
:=
:=...a bunch of functions
:=----------------------------------------------------
:=
:=when i try to compile the MAIN file, it gives me an error in the mylcd.c "no main() function found".
:=
:=Thanks,
:=mle
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515530 |
|
![](templates/subSilver/images/spacer.gif) |
mle Guest
|
Re: errors in include file |
Posted: Tue Jun 24, 2003 10:51 am |
|
|
Thank you,
That worked.
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515531 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|