View previous topic :: View next topic |
Author |
Message |
JM35
Joined: 10 Feb 2009 Posts: 10
|
multiple source files |
Posted: Tue Feb 10, 2009 12:12 pm |
|
|
Hello !
How to compile with PCWHD (Version 4.073, 44201 ) multiple source files ???
Do I have a multiple compilation unit ? I can't use headers, PCWHD tell me blabla "Function used but not defined ..." !
Code: | In main.c :
....
#include "LCD.h"
.....
In LCD.h :
#ifndef _H_LCD_
#define _H_LCD_
// prototypes ...
#endif
In LCD.c :
// functions .... |
I'm not using MPLAB. Just want to organize my code with 2 or 3 headers.
Thank's a lot ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 1:05 pm |
|
|
The traditional way of using multiple source files with CCS, is to #include
them all in the main source file. Then compile the main source file. |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 3:11 pm |
|
|
Thank's !
That's exactly what I'm doing ...
Code: |
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.c"
void main()
{
char msg[20] = {"Hello !"};
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
LCD_INIT();
while(1){
LCD_GOTO(6,2);
LCD_PUT_STRING(msg);
delay_ms(500);
LCD_CLEAR();
delay_ms(500);
}
}
|
In LCD.h :
Code: |
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "LCD.c"
#ifndef _H_LCD_
#define _H_LCD_
void LCD_INIT(void);
void LCD_SEND(char Octet, char INST_DATA);
void LCD_ENABLE(void);
void LCD_CLEAR(void);
void LCD_PUT_CHAR(char Car);
void LCD_PUT_STRING(char *ptr);
void LCD_GOTO(BYTE Col, BYTE Ligne);
#endif
|
In LCD.c :
Code: |
#define LCD_EN PIN_C5
#define LCD_RS PIN_A5
#define INSTRUCT 0
#define CARACT 1
void LCD_INIT(void)
{
// initialisation de l'afficheur LCD controlleur KS0066U
delay_ms(40); //30 ms d'après datasheet
LCD_SEND(0x33,INSTRUCT); delay_ms(10); // Mode 8 bits
LCD_SEND(0x32,INSTRUCT); delay_ms(10); // Mode 4 bits
LCD_SEND(0x2C,INSTRUCT); delay_us(50); // Display ON, Cursor OFF, Blink Off
LCD_SEND(0x06,INSTRUCT); delay_us(50); // Entry Mode Set : Increment Ram, No Shift Display
LCD_SEND(0x0C,INSTRUCT); delay_us(50);
LCD_CLEAR();
}
// etc ..... all others functions
|
What's the problem ???? |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 3:17 pm |
|
|
oops sorry, copy/paste error :
in main :
Code: | #include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.h" |
in LCD.h :
Code: | #include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "LCD.c" |
in LCD.c :
Code: |
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h" |
test_lcd is my project ... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 3:23 pm |
|
|
In the CCS method, you don't include the header files such as test_lcd.h
in each module. Remember, it's effectively one big file.
If you have a header file which has constants which are used by other
include files, then just #include that header file one time, in the main
source file, near the top of the file. |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 3:35 pm |
|
|
Thank you for your response !
So I try :
in main :
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.h"
in LCD.h : nothing ?
in LCD.c
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.h"
PCWHD don't compile ! Stop because didn't find lcd_init() ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 3:41 pm |
|
|
I don't know exactly what you're doing, because all your files have
similar sounding names.
See my post in this thread. It shows how to organize your main source
file:
http://www.ccsinfo.com/forum/viewtopic.php?t=18649 |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 3:52 pm |
|
|
my project's name is test_lcd
the main file is test_lcd.c :
Code: |
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\test_lcd.h"
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.c"
#include "C:\Temp2\Stage PIC\TP\TP2_LCD\Corrige\LCD.h"
void main()
{
char msg[20] = {"Hello !"};
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
LCD_INIT();
while(1){
LCD_GOTO(6,2);
LCD_PUT_STRING(msg);
delay_ms(500);
LCD_CLEAR();
delay_ms(500);
}
} |
then only one header : LCD.h
Code: |
void LCD_INIT(void);
void LCD_SEND(char Octet, char INST_DATA);
void LCD_ENABLE(void);
void LCD_CLEAR(void);
void LCD_PUT_CHAR(char Car);
void LCD_PUT_STRING(char *ptr);
void LCD_GOTO(BYTE Col, BYTE Ligne);
|
and the associated source : LCD.c
Code: |
// Broches du LCD :
#define LCD_EN PIN_C5
#define LCD_RS PIN_A5
#define INSTRUCT 0
#define CARACT 1
void LCD_INIT(void)
{
// initialisation de l'afficheur LCD controlleur KS0066U
delay_ms(40); //30 ms d'après datasheet
LCD_SEND(0x33,INSTRUCT); delay_ms(10); // Mode 8 bits
LCD_SEND(0x32,INSTRUCT); delay_ms(10); // Mode 4 bits
LCD_SEND(0x2C,INSTRUCT); delay_us(50); // Display ON, Cursor OFF, Blink Off
LCD_SEND(0x06,INSTRUCT); delay_us(50); // Entry Mode Set : Increment Ram, No Shift Display
LCD_SEND(0x0C,INSTRUCT); delay_us(50);
LCD_CLEAR();
}
void LCD_ENABLE(void)
{
// Génère une impulsion positive de 50 µs sur la broche EN du LCD
// Le bus de données 4 bits est pris en compte par le LCD
output_low(LCD_EN); // LCD désélectionné
delay_us(1);
output_high(LCD_EN);delay_us(100); // LCD sélectionné
output_low(LCD_EN); // LCD désélectionné
delay_us(1);
}
void LCD_SEND(char Octet, char INST_DATA)
{
// Envoi l'octet Octet au LCD
// Si INST_DATA = INSTRUCT => Envoi d'une instruction
// Si INST_DATA = CARACT => Envoi d'un caractère à afficher
output_bit(LCD_RS,INST_DATA);
delay_us(50);
// Envoi MSB de Commande au LCD :
if((Octet>>4)& 0x01)output_high(PIN_B1); else output_low(PIN_B1);
if((Octet>>5)& 0x01)output_high(PIN_B2); else output_low(PIN_B2);
if((Octet>>6)& 0x01)output_high(PIN_B4); else output_low(PIN_B4);
if((Octet>>7)& 0x01)output_high(PIN_B5); else output_low(PIN_B5);
LCD_ENABLE(); // Valide la donnée 4 bits
// Envoi LSB de Commande au LCD :
if(Octet & 0x01)output_high(PIN_B1); else output_low(PIN_B1);
if((Octet>>1)& 0x01)output_high(PIN_B2); else output_low(PIN_B2);
if((Octet>>2)& 0x01)output_high(PIN_B4); else output_low(PIN_B4);
if((Octet>>3)& 0x01)output_high(PIN_B5); else output_low(PIN_B5);
LCD_ENABLE();
delay_ms(1); // 2 envois séparés par au moins 40 µs
}
void LCD_CLEAR(void)
{
// Efface LCD, curseur retourne en haut à gauche
LCD_SEND(0x01,INSTRUCT); delay_ms(2); // > 1.53 ms
}
void LCD_PUT_CHAR(char Car)
{
// Affiche le caractère à la position courante du curseur
LCD_SEND(Car,CARACT);
}
void LCD_PUT_STRING(char *ptr)
{
// Affiche la chaine de caractères à la position courante du curseur
while(*ptr)LCD_PUT_CHAR(*ptr++);
}
void LCD_GOTO(BYTE Col, BYTE Ligne)
{
// positionne le curseur Ligne, Colonne
// Ligne = 1 ou 2
// Col = 1 à 40
BYTE address;
if(Ligne<=1)address = 0; else address=0x40;
address+=Col-1;
LCD_SEND(0x80|address,INSTRUCT);
}
|
That's all ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 4:07 pm |
|
|
What's in this file ? |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 4:18 pm |
|
|
Created by wizard !
Quote: |
#include <18F452.h>
#device ICD=TRUE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=20000000)
Code: |
I don't modify it ...
|
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 4:23 pm |
|
|
Your lcd.h file has the function prototypes it in. The compiler needs to
see them before it sees any calls to the functions. All you need to do to
fix it, is to change the order of your #include statements so the lcd.h
file comes before the .c file. Example:
Quote: | #include "test_lcd.h"
#include "LCD.h"
#include "LCD.c" |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 10, 2009 4:25 pm |
|
|
Also, change this to NOLVP. Do that in all your programs. You're not
using low voltage programming mode. |
|
|
JM35
Joined: 10 Feb 2009 Posts: 10
|
|
Posted: Tue Feb 10, 2009 4:32 pm |
|
|
OK thank's a lot it's working fine now !
I suppose it's the same way if I need more header files ...
Not a very standard C !
Bye and thank you ! |
|
|
|