2018-09-21 06:42 AM
Hi,
How can i define global variable in COSMIC C Compiler for STM8S? Is there any document which can explain for global variable definition in COSMIC C Compiler?
Regards,
Nandish Jasani.
2018-09-23 07:42 AM
There is nothing Comsic-specific here. It works just as in any other C compiler: Any variable declared at file-scope that does not have static storage is global.
Philipp
2018-09-23 09:59 PM
Thanks Philipp for your reply,
Actually i have main.h file where i define some constants and function declarations. I include this file in my main.c program. But in main.h file when i define constant array variable, compiler gives the error. Below is the error in Cosmic Compiler.
In fact any variable i defined in main.h file, compiler gives error of multiply defined.
Is there any way to solve this issue?
[#error clnk Debug\tsd.lkf:54 Debug\main.o: symbol _sddds multiply defined (Debug\stm8s_it.o)
The command: "clnk -m Debug\tsd.map -l"C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\Lib" -o Debug\tsd.sm8 Debug\tsd.lkf " has failed, the returned value is: 1
exit code=1.]
Below is the main.h and main.c file.
Regards,
Nandish Jasani.
// This is main.h file
#include <iostm8s.h>
#include <stm8s_it.h>
#define HSE 0xb4
#define LSI 0xd2
#define HSI 0xe1
#define F_CPU 16000000UL
#define RIM _asm("rim")
#define SIM _asm("sim")
void ControllerInitialization(void);
void WatchDogInitialization(void);
void SwitchClockSourceToHSE(void);
void WatchDogReset(void);
void DIOConfiguration(void);
void Timer4Initialization(void);
void Delay250uSecond(void);
void Delay1mSecond(void);
void Delay100mSecond(void);
void Delay250mSecond(void);
void Delay500mSecond(void);
void Delay1Second(void);
void DLEDIOConfiguration(void);
void SDROWIOConfiguration(void);
void SDCOLIOConfiguration(void);
void KEYIOConfiguration(void);
void ELEVATORIOConfiguration(void);
_Bool SWEN @CLK_SWCR:1;
_Bool SWBSY @CLK_SWCR:0;
_Bool ODR3 @PE_ODR:3;
_Bool CEN @TIM4_CR1:0;
_Bool UIF @TIM4_SR:0;
#define DLED ODR3
#define ONDLED DLED = 0
#define OFFDLED DLED = 1
#define ONTIM4 CEN = 1
#define OFFTIM4 CEN = 0
#define CLRTIM4INT UIF = 0
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0xeb, 0xeb, 0xdb, 0xbb, 0x7b, 0x01},
{0x99, 0x66, 0xee, 0xee, 0xdd, 0xbb, 0x77, 0x00},
{0x99, 0x66, 0xee, 0xe9, 0xde, 0xbe, 0x76, 0x09},
{0x9e, 0x6c, 0xea, 0xe6, 0xd6, 0xb0, 0x7e, 0x0e},
{0x90, 0x67, 0xe7, 0xe1, 0xde, 0xbe, 0x76, 0x09},
{0x99, 0x66, 0xe7, 0xe1, 0xd6, 0xb6, 0x76, 0x09},
{0x90, 0x6e, 0xee, 0xed, 0xdb, 0xbb, 0x7b, 0x0b},
{0x99, 0x66, 0xe6, 0xe9, 0xd6, 0xb6, 0x76, 0x09},
{0x99, 0x66, 0xe6, 0xe6, 0xd8, 0xb1, 0x76, 0x09},
{0x99, 0x66, 0xe6, 0x96, 0xe6, 0xe6, 0x66, 0x99},
{0x9b, 0x63, 0xeb, 0x9b, 0xeb, 0xeb, 0x6b, 0x91},
{0x99, 0x66, 0xee, 0x9e, 0xed, 0xeb, 0x67, 0x90},
{0x99, 0x66, 0xee, 0x99, 0xee, 0xee, 0x66, 0x99},
{0x9e, 0x6c, 0xea, 0x96, 0xe6, 0xe0, 0x6e, 0x9e},
{0x90, 0x67, 0xe7, 0x91, 0xee, 0xee, 0x66, 0x99},
{0x99, 0x66, 0xe7, 0x91, 0xe6, 0xe6, 0x66, 0x99},
{0x90, 0x6e, 0xee, 0x9d, 0xeb, 0xeb, 0x6b, 0x9b},
{0x99, 0x66, 0xe6, 0x99, 0xe6, 0xe6, 0x66, 0x99},
{0x99, 0x66, 0xe6, 0x96, 0xe8, 0xe1, 0x66, 0x99},
{0xe9, 0xc6, 0xa6, 0x66, 0x66, 0x06, 0xe6, 0xe9},
{0xeb, 0xc3, 0xab, 0x6b, 0x6b, 0x0b, 0xeb, 0xe1},
{0xe9, 0xc6, 0xae, 0x6e, 0x6d, 0x0b, 0xe7, 0xe0},
{0xe9, 0xc6, 0xae, 0x69, 0x6e, 0x0e, 0xe6, 0xe9},
{0xee, 0xcc, 0xaa, 0x66, 0x66, 0x00, 0xee, 0xee},
{0xe0, 0xc7, 0xa7, 0x61, 0x6e, 0x0e, 0xe6, 0xe9},
{0xe9, 0xc6, 0xa7, 0x61, 0x66, 0x06, 0xe6, 0xe9},
{0xe0, 0xce, 0xae, 0x6d, 0x6b, 0x0b, 0xeb, 0xeb},
{0xe9, 0xc6, 0xa6, 0x69, 0x66, 0x06, 0xe6, 0xe9},
{0xe9, 0xc6, 0xa6, 0x66, 0x68, 0x01, 0xe6, 0xe9},
{0x09, 0x76, 0x76, 0x16, 0xe6, 0xe6, 0x66, 0x99},
{0x0b, 0x73, 0x7b, 0x1b, 0xeb, 0xeb, 0x6b, 0x91},
{0x09, 0x76, 0x7e, 0x1e, 0xed, 0xeb, 0x67, 0x90},
{0x09, 0x76, 0x7e, 0x19, 0xee, 0xee, 0x66, 0x99},
{0x0e, 0x7c, 0x7a, 0x16, 0xe6, 0xe0, 0x6e, 0x9e},
{0x00, 0x77, 0x77, 0x11, 0xee, 0xee, 0x66, 0x99},
{0x09, 0x76, 0x77, 0x11, 0xe6, 0xe6, 0x66, 0x99},
{0x00, 0x7e, 0x7e, 0x1d, 0xeb, 0xeb, 0x6b, 0x9b},
{0x09, 0x76, 0x76, 0x19, 0xe6, 0xe6, 0x66, 0x99},
{0x09, 0x76, 0x76, 0x16, 0xe8, 0xe1, 0x66, 0x99},
{0x99, 0x66, 0x76, 0x16, 0x66, 0x66, 0x66, 0x99},
{0x9b, 0x63, 0x7b, 0x1b, 0x6b, 0x6b, 0x6b, 0x91},
{0x99, 0x66, 0x7e, 0x1e, 0x6d, 0x6b, 0x67, 0x90},
{0x99, 0x66, 0x7e, 0x19, 0x6e, 0x6e, 0x66, 0x99},
{0x9e, 0x6c, 0x7a, 0x16, 0x66, 0x60, 0x6e, 0x9e},
{0x90, 0x67, 0x77, 0x11, 0x6e, 0x6e, 0x66, 0x99},
{0x99, 0x66, 0x77, 0x11, 0x66, 0x66, 0x66, 0x99},
{0x90, 0x6e, 0x7e, 0x1d, 0x6b, 0x6b, 0x6b, 0x9b},
{0x99, 0x66, 0x76, 0x19, 0x66, 0x66, 0x66, 0x99},
{0x99, 0x66, 0x76, 0x16, 0x68, 0x61, 0x66, 0x99},
{0x09, 0xe6, 0xe6, 0xd6, 0xb6, 0xb6, 0xb6, 0xb9},
{0x0b, 0xe3, 0xeb, 0xdb, 0xbb, 0xbb, 0xbb, 0xb1},
{0x09, 0xe6, 0xee, 0xde, 0xbd, 0xbb, 0xb7, 0xb0},
{0x09, 0xe6, 0xee, 0xd9, 0xbe, 0xbe, 0xb6, 0xb9},
{0x0e, 0xec, 0xea, 0xd6, 0xb6, 0xb0, 0xbe, 0xbe},
{0x00, 0xe7, 0xe7, 0xd1, 0xbe, 0xbe, 0xb6, 0xb9},
{0x09, 0xe6, 0xe7, 0xd1, 0xb6, 0xb6, 0xb6, 0xb9},
{0x00, 0xee, 0xee, 0xdd, 0xbb, 0xbb, 0xbb, 0xbb},
{0x09, 0xe6, 0xe6, 0xd9, 0xb6, 0xb6, 0xb6, 0xb9},
{0x09, 0xe6, 0xe6, 0xd6, 0xb8, 0xb1, 0xb6, 0xb9},
{0x99, 0x66, 0x66, 0x96, 0x66, 0x66, 0x66, 0x99},
{0x9b, 0x63, 0x6b, 0x9b, 0x6b, 0x6b, 0x6b, 0x91},
{0x99, 0x66, 0x6e, 0x9e, 0x6d, 0x6b, 0x67, 0x90},
{0x99, 0x66, 0x6e, 0x99, 0x6e, 0x6e, 0x66, 0x99},
{0x9e, 0x6c, 0x6a, 0x96, 0x66, 0x60, 0x6e, 0x9e},
{0x90, 0x67, 0x67, 0x91, 0x6e, 0x6e, 0x66, 0x99},
{0x99, 0x66, 0x67, 0x91, 0x66, 0x66, 0x66, 0x99},
{0x90, 0x6e, 0x6e, 0x9d, 0x6b, 0x6b, 0x6b, 0x9b},
{0x99, 0x66, 0x66, 0x99, 0x66, 0x66, 0x66, 0x99},
{0x99, 0x66, 0x66, 0x96, 0x68, 0x61, 0x66, 0x99},
{0x99, 0x66, 0x66, 0x66, 0x86, 0x16, 0x66, 0x99},
{0x9b, 0x63, 0x6b, 0x6b, 0x8b, 0x1b, 0x6b, 0x91},
{0x99, 0x66, 0x6e, 0x6e, 0x8d, 0x1b, 0x67, 0x90},
{0x99, 0x66, 0x6e, 0x69, 0x8e, 0x1e, 0x66, 0x99},
{0x9e, 0x6c, 0x6a, 0x66, 0x86, 0x10, 0x6e, 0x9e},
{0x90, 0x67, 0x67, 0x61, 0x8e, 0x1e, 0x66, 0x99},
{0x99, 0x66, 0x67, 0x61, 0x86, 0x16, 0x66, 0x99},
{0x90, 0x6e, 0x6e, 0x6d, 0x8b, 0x1b, 0x6b, 0x9b},
{0x99, 0x66, 0x66, 0x69, 0x86, 0x16, 0x66, 0x99},
{0x99, 0x66, 0x66, 0x66, 0x88, 0x11, 0x66, 0x99},
};
// This is main.c file
#include <main.h>
void main(void)
{
ControllerInitialization();
WatchDogInitialization();
SwitchClockSourceToHSE();
Timer4Initialization();
ONTIM4;
RIM;
while (1)
{
WatchDogReset();
}
}
void ControllerInitialization(void)
{
CFG_GCR = 0;
FLASH_CR1 = 0x08;
RST_SR = 0xff;
}
void WatchDogInitialization(void)
{
IWDG_KR = 0x55;
IWDG_PR = 3;
IWDG_RLR = 0xff;
IWDG_KR = 0xcc;
}
void WatchDogReset(void)
{
IWDG_KR = 0xaa;
}
void SwitchClockSourceToHSE(void)
{
SWEN = 1;
CLK_SWR = HSE;
while (CLK_SWR != CLK_CMSR){ WatchDogReset(); }
while (SWBSY){ WatchDogReset(); }
}
void Timer4Initialization(void)
{
TIM4_CR1 = 0x04;
// CLK_CNT = fmaster/2^(TIM4_PSCR).
// In this case fmaster = 16MHz.
// Prescaler is 7 i.e. 128.
// CLK_CNT = 16MHz/128 = 125KHz = 8uSec
TIM4_PSCR = 0x07;
// Auto reload value is 250 i.e. 8uSec * 250 = 2mSec Timer.
TIM4_ARR = 250;
TIM4_IER = 0x01;
}
2018-09-24 02:26 AM
I suggest:
Put an extern declaration into the .h file:
extern const unsigned char sddds[100][8];
Move the definition to a .c file.
Philipp