Built-in Routines
The mikroC PRO for ARM compiler provides a set of useful built-in utility functions.
The Lo
, Hi
, Higher
, Highest
, LoWord
, HiWord
routines are implemented as macros. If you want to use these functions you must include built_in.h
header file (located in the inlclude
folder of the compiler) into your project.
The Delay_us
and Delay_ms
routines are implemented as “inline”; i.e. code is generated in the place of a call, so the call doesn’t count against the nested call limit.
The Vdelay_ms
, Vdelay_advanced_ms
, Delay_Cyc
, Delay_Cyc_Long
, Get_Fosc_kHz
and Get_Fosc_Per_Cyc
are actual C routines. Their sources can be found in Delays.c
file located in the uses
folder of the compiler.
Lo
Prototype |
#define Lo(param) ((char *)¶m)[0] |
---|---|
Description |
The function returns low byte of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Low byte of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = Lo(d); // Equals 0x78 Lo(d) = 0xAA; // d equals 0x123456AA |
Notes |
None. |
Hi
Prototype |
#define Hi(param) ((char *)¶m)[1] |
---|---|
Description |
The function returns high byte of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
High byte of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = Hi(d); // Equals 0x56 Hi(d) = 0xAA; // d equals 0x1234AA78 |
Notes |
None. |
Higher
Prototype |
#define Higher(param) ((char *)¶m)[2] |
---|---|
Description |
The function returns higher byte of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Higher byte of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = Higher(d); // Equals 0x34 Higher(d) = 0xAA; // d equals 0x12AA5678 |
Notes |
None. |
Highest
Prototype |
#define Highest(param) ((char *)¶m)[3] |
---|---|
Description |
The function returns highest byte of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Highest byte of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = Highest(d); // Equals 0x12 Highest(d) = 0xAA; // d equals 0xAA345678 |
Notes |
None. |
LoWord
Prototype |
unsigned int LoWord(unsigned long param); |
---|---|
Description |
The function returns low word of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Low word of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = LoWord(d); // Equals 0x5678 LoWord(d) = 0xAAAA; // d equals 0x1234AAAA |
Notes |
None. |
HiWord
Prototype |
unsigned int HiWord(unsigned long param); |
---|---|
Description |
The function returns high word of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
High word of |
Requires |
Nothing. |
Example |
d = 0x12345678; tmp = HiWord(d); // Equals 0x1234 HiWord(d) = 0xAAAA; // d equals 0xAAAA5678 |
Notes |
None. |
LoLongWord
Prototype |
#define LoLongWord(param) ((unsigned long*)¶m)[0] |
---|---|
Description |
The function returns low longword of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Low longword of |
Requires |
Nothing. |
Example |
d = 0x1122334455667788; tmp = LoLongWord(d); // Equals 0x55667788 LoLongWord(d) = 0xAAAAAAAA; // d equals 0x11223344AAAAAAAA |
Notes |
None. |
HiLongWord
Prototype |
#define HiLongWord(param) ((unsigned long*)¶m)[1] |
---|---|
Description |
The function returns high longword of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
High word of |
Requires |
Nothing. |
Example |
d = 0x1122334455667788; tmp = HiLongWord(d); // Equals 0x11223344 HiLongWord(d) = 0xAAAAAAAA; // d equals 0xAAAAAAAA55667788 |
Notes |
None. |
Delay_us
Prototype |
void Delay_us(const unsigned long time_in_us); |
---|---|
Description |
Creates a software delay in duration of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
Delay_us(10); /* Ten microseconds pause */ |
Notes |
None. |
Delay_ms
Prototype |
void Delay_ms(const unsigned int time_in_ms); |
---|---|
Description |
Creates a software delay in duration of This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
Delay_ms(1000); /* One second pause */ |
Notes |
For generating delays with variable as input parameter use the Vdelay_ms routine. |
Vdelay_ms
Prototype |
void Vdelay_ms(unsigned Time_ms); |
---|---|
Description |
Creates a software delay in duration of |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
unsignedpause = 1000; ... Vdelay_ms(pause); // ~ one second pause |
Notes |
|
VDelay_Advanced_ms
Prototype |
void VDelay_Advanced_ms(unsigned time_in_ms, unsigned Current_Fosc_kHz); |
---|---|
Description |
Creates a software delay in duration of |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
pause = 1000; fosc = 10000; VDelay_Advanced_ms(pause, fosc); // Generates approximately one second pause, for a oscillator frequency of 10 MHz |
Notes |
Note that |
Delay_Cyc
Prototype |
void Delay_Cyc(unsigned int x, unsigned int y); |
---|---|
Description |
Creates a delay based on MCU clock. Delay lasts for |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
Delay_Cyc(1, 10); /* 1x16384 + 10 = 16394 cycles pause */ |
Notes |
|
Delay_Cyc_Long
Prototype |
void Delay_Cyc_Long(unsigned long CycNo); |
---|---|
Description |
Creates a delay based on MCU clock. Delay lasts for |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
Delay_Cyc_Long(16394); // 16394 cycles pause |
Notes |
|
Clock_kHz
Prototype |
unsigned long Clock_kHz(); |
---|---|
Description |
Function returns device clock in kHz, rounded to the nearest integer. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
None. |
Returns |
Device clock in kHz, rounded to the nearest integer. |
Requires |
Nothing. |
Example |
unsigned long clk; ... clk = Clock_kHz(); |
Notes |
None. |
Clock_Mhz
Prototype |
unsigned long Clock_MHz(); |
---|---|
Description |
Function returns device clock in MHz, rounded to the nearest integer. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. |
Parameters |
None. |
Returns |
Device clock in MHz, rounded to the nearest integer. |
Requires |
Nothing. |
Example |
unsigned long clk; ... clk = Clock_Mhz(); |
Notes |
None. |
Get_Fosc_kHz
Prototype |
unsigned long Get_Fosc_kHz(); |
---|---|
Description |
Function returns device clock in kHz, rounded to the nearest integer. Note that |
Parameters |
None. |
Returns |
Device clock in kHz, rounded to the nearest integer. |
Requires |
Nothing. |
Example |
unsigned long clk; ... clk = Get_Fosc_kHz(); |
Notes |
None. |
Get_Fosc_Per_Cyc
Prototype |
unsigned int Get_Fosc_Per_Cyc(); |
---|---|
Description |
Function returns device's clock per cycle, rounded to the nearest integer. Note that |
Parameters |
None. |
Returns |
Device's clock per cycle, rounded to the nearest integer. |
Requires |
Nothing. |
Example |
unsigned int clk_per_cyc; ... clk_per_cyc = Get_Fosc_Per_Cyc(); |
Notes |
None. |
SystemReset
Prototype |
void SystemReset(); |
---|---|
Description |
This function will perform a software reset of the entire device. The processor and all peripherals are reset and all device registers will return to their default values
|
Parameters |
None. |
Returns |
Nothing. |
Requires |
Nothing. |
Example |
SystemReset(); |
Notes |
None. |
CPU_REG_GET
Prototype |
unsigned long CPU_REG_GET(const char reg); |
---|---|
Description |
Function returns the value of the core register, based upon the argument entered. |
Parameters |
Parameter must be a constant from the enumerated built-in constants list, which can be found at the bottom of this page. |
Returns |
Value of the core register. |
Requires |
Nothing. |
Example |
unsigned long register_value ; register_value = CPU_REG_GET(CPU_PRIMASK); |
Notes |
None. |
CPU_REG_SET
Prototype |
void CPU_REG_SET(const char reg, unsigned long value); |
---|---|
Description |
Function sets the value of the core register, based upon the |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
CPU_REG_SET(CPU_PRIMASK); |
Notes |
None. |
RestoreInterrupts
Prototype |
void RestoreInterrupts(unsigned long primask); |
---|---|
Description |
Restores (enables or disables) core interrupts based on the last PRIMASK register value given as a routine parametar. |
Parameters |
None. |
Returns |
Returns the value stored in the PRIMASK register before the interrupts were enabled/disabled. |
Requires |
Nothing. |
Example |
RestoreInterrupts(CPU_PRIMASK); |
Notes |
None. |
EnableInterrupts
Prototype |
unisgned long EnableInterrupts(); |
---|---|
Description |
This function enables the processor interrupt and allows the processor to respond to interrupts.
|
Parameters |
None. |
Returns |
Returns the value stored in the PRIMASK register. |
Requires |
Nothing. |
Example |
status_value = EnableInterrupts(); |
Notes |
None. |
DisableInterrupts
Prototype |
unsigned long DisableInterrupts(); |
---|---|
Description |
This function disables the processor interrupt and prevents the processor from receiving interrupts.
|
Parameters |
Returns the value stored in the PRIMASK register. |
Returns |
Nothing. |
Requires |
Nothing. |
Example |
status_value = DisableInterrupts(); |
Notes |
None. |
NVIC_IntEnable
Prototype |
void NVIC_IntEnable(const unsinged long ivt); |
---|---|
Description |
This procedure enables an interrupt vector. The specified interrupt vector is enabled in the interrupt controller.
|
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
NVIC_IntEnable(IVT_INT_TIMER0A); |
Notes |
The list of the available interrupt vectors be be seen in Code Assistant, by typing IVT and pressing Ctrl + Space,
|
NVIC_IntDisable
Prototype |
void NVIC_IntDisable(const unsigned long ivt); |
---|---|
Description |
This procedure disables an interrupt vector. The specified interrupt vector is disabled in the interrupt controller.
|
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
NVIC_IntDisable(IVT_INT_TIMER0A); |
Notes |
The list of the available interrupt vectors be be seen in Code Assistant, by typing IVT and pressing Ctrl + Space,
|
Core Registers | ||||||
---|---|---|---|---|---|---|
CPU_APSR | CPU_IAPSR | CPU_EAPSR | CPU_XPSR | CPU_IPSR | CPU_EPSR | CPU_IEPSR |
CPU_MSP | CPU_PSP | CPU_PRIMASK | CPU_BASEPRI | CPU_BASEPRI | CPU_BASEPRI_MAX | CPU_CONTROL |
What do you think about this topic ? Send us feedback!