Dear Sir i want to use with variables that defined at the main, at the file of functions. i try to add extern to the variables, but it send me an error massege like: non address/-constant initializer. when i added the sign "()" after the name of the variables i accept an error massege like: error L102: external attribute mismatch and error L118: reference made to erroneous external how can i correct in thank you
too vague a question 1) C or assembler? 2) show examples of both where it is defined and where it is accessed. Erik
This is bog-standard 'C'; nothing specific to Keil at all - so see any 'C' textbook. Basically you must have exactly one definition for each & every identifier; You may have as many 'extern' declarations as you like.
file.c // definitions char tom = 0; // definition with initialisation int ***; long harry;
file.h // declarations extern char tom; // NO initialisation!! extern int ***; extern long harry;
i will clarify my problem, i wrote with c51 and i attached my program. my project based on example code of Atmel Co. and it include few files. i added program at the main.c and i try to use with variable also at the main and the usb_task.c file the code of the main is:
#include "config.h" #include "modules/scheduler/scheduler.h" #include "lib_mcu/reg_5131.h" /*---------------------------------*/ char serial_data; char data_from_adc ; char data_save_msb; char data_save_lsb; int int1=1; bit transmit_completed= 0; int i; /*-----------------------------------*/ void main (void) { ... /*------------------*/ the another file from this project is: #include "config.h" #include "usb_task.h" #include "lib_mcu\usb\usb_drv.h" #include "modules\usb_kbd_enum\usb_kbd_enum.h" #include "modules\timer_soft\timer_soft.h" //#include "lib_board\lcd_twi\lcd_twi.h" //#include "lib_board\kbd_4_4\kbd_4_4.h" / bit usb_connected; bit usb_connected_stored; bit usb_configured_stored; Uchar usb_sof_counter; Uchar usb_kbd_state; Uchar transmit_no_key; Union16 idata scan_key; Uchar key_hit; Uchar shift_key; extern Uchar usb_configuration_nb; //Uchar code usb_keys[]= { b[1], b[2], b[3], b[4] } extern char data_save_msb(); /*-------------*/ void main etc...
the another file from this project is: #include "config.h" #include "usb_task.h" #include "lib_mcu\usb\usb_drv.h" #include "modules\usb_kbd_enum\usb_kbd_enum.h" #include "modules\timer_soft\timer_soft.h" //#include "lib_board\lcd_twi\lcd_twi.h" //#include "lib_board\kbd_4_4\kbd_4_4.h" / bit usb_connected; bit usb_connected_stored; bit usb_configured_stored; Uchar usb_sof_counter; Uchar usb_kbd_state; Uchar transmit_no_key; Union16 idata scan_key; Uchar key_hit; Uchar shift_key; extern Uchar usb_configuration_nb; //Uchar code usb_keys[]= { b[1], b[2], b[3], b[4] } extern char data_save_msb(); /*-------------*/ void main etc...
#include "config.h" #include "usb_task.h" #include "lib_mcu\usb\usb_drv.h" #include "modules\usb_kbd_enum\usb_kbd_enum.h" #include "modules\timer_soft\timer_soft.h" //#include "lib_board\lcd_twi\lcd_twi.h" //#include "lib_board\kbd_4_4\kbd_4_4.h" / bit usb_connected; bit usb_connected_stored; bit usb_configured_stored; Uchar usb_sof_counter; Uchar usb_kbd_state; Uchar transmit_no_key; Union16 idata scan_key; Uchar key_hit; Uchar shift_key; extern Uchar usb_configuration_nb; //Uchar code usb_keys[]= { b[1], b[2], b[3], b[4] } extern char data_save_msb(); /*-------------*/ void main etc...
please look at the last reply
as stated above "This is bog-standard 'C'; nothing specific to Keil at all - so see any 'C' textbook." Erik
Your two files both seem to contain a definition of main. Other than that, they seem to be entirely unrelated! What exactly is your problem?!