How to assign variables to the specified address
For example:
unsigned char temp_A@0x00; //Define the unsigned variable temp_A and force its address to be 0x00
unsigned char temp_B@0x100; //Define an unsigned variable temp_B and force its address to be 0x100
@tiny unsigned char temp_C; //Define an unsigned variable temp_C, and the compiler will automatically assign an address to it in RAM with an address less than 0x100
@near unsigned char temp_D; //Define an unsigned variable temp_D, and the compiler will automatically assign an address to it in the RAM with an address greater than 0xFF
In addition, you can also use the pseudo-instruction "pragma" to define functions or variables to the specified secTIon, for example:
#pragma secTIon [name] // Define the uninitialized variables defined below to .name secTIon
Unsigned char data1;
Unsigned int data2;
... (any variable that needs to be defined in .name secTIon)
...
#pragma section [] // Return to the normal section.
Note: The pragma directive can be used to locate functions, initialize variables or uninitialized variables. These three are distinguished by different brackets.
(Name): code
[Name]: Uninitialized variable
{name}: Initialization variable
How to use assembly language in COSMIC C files
There are two common ways to use assembly language in COSMIC C files: Use #asm …#endasm combination format
Or _asm ("..."); single-line format.
Example 1:
unsigned char temp_A;
Void func1 (void)
{
. ..
#asm
PUSH A
LD A, (X)
LD _temp_A, A
POP A
#endasm
. ..
}
Note: To use global variables in the C embedded assembly environment, add an underscore "_" before the name of the global variable.
Example 2:
Void func1 (void)
{
. ..
_asm("rim");
_asm("nop");
. ..
}
How to observe the final allocation of RAM/FLASH/EEPROM
In the Project-"settings-"linker tab, select Category as Output, and then check Generate Map File.
After clicking the OK button, compile and link the project again, and if successful, a .map file will be generated in the project output directory (in this example, under the C:\STM8_NewProject1\debug directory). This file lists the allocation and usage of RAM/FLASH/EEPROM in detail.
How to generate output file in hex format
In the Project-"settings-"PostBuild option page, add the following command in the commands column:
chex –fi -o $(OutputPath)$(TargetSName).hex $(OutputPath)$(TargetSName).sm8
Compile and link the project again, and if successful, a .hex file will be generated in the project output directory (in this example, under the C:\STM8_NewProject1\debug directory).
What is MEMORY MODEL
STM8's C compiler supports multiple memory modes. Users can choose the most suitable configuration according to the needs of the application. You can choose to use 2-byte addressing mode (only for programs within 64k) or 3-byte addressing mode according to your needs. You can also specify which area of ​​the memory the variable is defined in by default: inside the zero page or outside the zero page. The following is a brief description of several MEMORY MODELs to choose from.
In the Project-"settings-"C Complier tab, select Category as General, and there is a Memory Models option bar as follows:
There are 4 kinds of MEMORY MODEL to choose from in the drop-down menu:
The program address space is within 64K (that is, the program capacity is less than 32K)
mods0,
modsl0
The program address is above 64K (that is, the program capacity is greater than 32K)
mods
modsl
MODS0MODSL0MODSMODSL
Name Stack Short
Short stack mode Stack Long
Stack Short
Short stack mode Stack Long
Long stack mode
Program address space The address space used by the program is in the 64K range The address space used by the program exceeds the 64K range
Default pointer type The function pointer and data pointer default to @near (2 bytes) The function pointer defaults to @far (address is 3 bytes);
The data pointer defaults to @near
Default type of global variables The address of all global variables is 1 byte by default. For variables whose addresses exceed 1 byte, @near must be used to define all global variables as Long by default. If you want to define the variable address as 1 byte, you must use @tiny to define the address of all global variables as 1 byte by default. For variables whose addresses exceed 1 byte, @near must be used to define all global variables as Long by default. To define the variable address as 1 byte, it must be defined with @tiny
The role of .lkf files
The .lkf file determines how to allocate RAM/ROM space specifically when the program is linked. In the Project Settings-Linker-Category (Input) option page, when the "Auto" selection box is selected, the system automatically generates the .LKF file, otherwise it is specified by the user.
When the "Auto" checkbox is checked, the .lkf file will be automatically generated in the debug/ and release/ directories under the project's main directory. Take the lkf file of the at45DBXX Project shown in the above figure as an example to further understand the .lkf.
In .lkf, the line starting with "#" is a comment line. To facilitate the user's understanding, the original comment is deleted and replaced by a Chinese comment as follows:
# Define (+seg) a constant segment (.const), start (b) at 0x8080, and allocate (m) 0x1ff80 bytes (that is, no more than
# 0x27FFF), name the section (n) as .const (the same name as the reserved word of the constant section), the initial value of the variable that needs to be initialized is stored
# Put in this paragraph (-it)
+seg .const -b 0x8080 -m 0x1ff80 -n .const -it
# Define (+seg) a program segment (.text), followed by (-a) after the .const segment (and .const are located at 0x8080 –
# 0x27FFF), give the section a name (n). text (the same name as the reserved word of the block).
+seg .text -a .const -n .text
# Define (+seg) an EEPROM segment (.eeprom), starting (b) at 0x4000, and the maximum allocation (m) 0x800 bytes (that is, not exceeding
#过0x47FF), give the section a name (n). eeprom (the same name as the reserved word in the EEPROM segment).
+seg .eeprom -b 0x4000 -m 0x800 -n .eeprom
# .bsct section serves global variables that need to be initialized within page 0 (address less than 0x100) (such as @tiny char a = 9;)
+seg .bsct -b 0x0 -m 0x100 -n .bsct
# .ubsct section serves global variables defined in page 0 (address less than 0x100) that do not need to be initialized (such as @tiny char b;)
+seg .ubsct -a .bsct -n .ubsct
# .bit represents the bit field segment. After definition, you can use the _Bool variable in the program (such as _Bool c = 1;), and -id represents that the segment needs to be initialized.
+seg .bit -a .ubsct -n .bit -id
# This is the ST7 era (STM8 is developed based on ST7) due to the small physical stack and slow speed, the use of memory to simulate the workaround of the stack.
+seg .share -a .bit -n .share -is
# .data section serves global variables that need to be initialized outside of page 0 (address greater than 0xFF) (such as @near char d = 8;)
+seg .data -b 0x100 -m 0x1300 -n .data
# .bss section serves global variables defined in page 0 (address greater than 0xFF) that do not need to be initialized (such as @ near char e;)
+seg .bss -a .data -n .bss
The # section definition ends, and the variables, constants, and programs in the libraries and Obj files placed below are allocated in accordance with the above regulations.
#Initialization
crtsi0.sm8
#User Program
Debug\main.o
…
# Some necessary cosmic libraries
libis0.sm8
libm0.sm8
# Redefine the constant section, starting at 0x8000, used to place the interrupt vector table (STM8 hardware determines this location)
# -K is used to optimize the redundant code of the program. For details, please refer to the cosmic user manual.
+seg .const -b 0x8000 –k
# Interrupt vector
Debug\stm8_interrupt_vector.o
#Defines three variables for system initialization
+def __endzp=@.ubsct # end of uninitialized zpage
+def __memory=@.bss # end of bss segment
+def __stack=0x17ff # Different chips have different __stack content, which is automatically generated by the system
How to implement bit manipulation
The Cosmic C compiler supports the operation of bit variables, which can be defined as _Bool type. Variables of type _Bool only contain two values ​​true (1) or false (0). If you assign an expression to the _Bool variable, the compiler compares the expression with 0, and then assigns the Boolean value to the _Bool variable. Therefore, the value of any integer or expression can be assigned to the _Bool variable. However, Boolean variables cannot be defined as bit arrays, they can only be defined as structures or unions. Moreover, the _Bool variable will be packed into bytes.
The compiler will pack all global _Bool variables into bytes and store them in the .bit section. Local _Bool variables will also be packed into bytes. But the parameter of type _Bool will be expanded into a single byte.
For the specific definition and use of bit variables, please refer to the following examples:
Define bit variables:
_Bool in_range;
_Bool p_valid;
char *ptr;
Use bit variables:
in_range = (value 》= 10) && (value 《= 20);
p_valid = ptr; /* p_valid is true if ptr not 0 */
if (p_valid && in_
When using bit variables, if the following error is prompted when the program is compiled:
#error clnk Debug\example.lkf:1 no default placement for segment .bit
The command: "clnk -l" C:\Program Files\COSMIC\CXSTM8_16K_4.2.10\Lib" -o Debug\example.sm8 -mDebug\example.map -sa Debug\example.lkf "has failed, the returned value is : 1
exit code=1.
Actually, there is no .bit section defined in the project. Follow the steps below to manually add the .bit section:
Open the project link configuration window: Project-Settings-Linker, select the Input directory item
Define a .bit section in Zero page or Ram.
Then recompile it.
ZGAR Vape Pods 1.0
ZGAR electronic cigarette uses high-tech R&D, food grade disposable pods and high-quality raw material. A new design of gradient our disposable vape is impressive.We equip with breathing lights in the vape pen and pods.
Our team has very high requirements for product quality, taste allocation and packaging design. Designers only use Hong Kong designers, e-cigarette liquid only imports from the United States, materials are food grade, and assembly factory wants medical grade without ground workshop.
We offer best price, high quality Pod System Vape,Pods Systems Touch Screen,Empty Pod System, Pod Vape System,Disposable Pod device,Vape Pods to all over the world.
ZGAR Vape 1.0 Pods,ZGAR Vape Pods 1.0 ,Pod Systems,Atomizer, E-cigarette, Empty Pod Vape Manufacturer and Supplier in China
Zgar International (M) SDN BHD , https://www.zgarvapepen.com