Built-in Routines
The mikroC PRO for 8051 compiler provides a set of useful built-in utility functions.
The Lo
, Hi
, Higher
, Highest
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
, Delay_Cyc
and Get_Fosc_kHz
are actual C routines. Their sources can be found in Delays.c
file located in the uses
folder of the compiler.
Lo
Prototype |
unsigned short Lo(long number); |
---|---|
Returns |
Lowest 8 bits (byte)of |
Description |
Function returns the lowest 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. |
Requires |
Arguments must be variable of scalar type (i.e. Arithmetic Types and Pointers). |
Example |
d = 0x1AC30F4; tmp = Lo(d); // Equals 0xF4 |
Hi
Prototype |
unsigned short Hi(long number); |
---|---|
Returns |
Returns next to the lowest byte of |
Description |
Function returns next to the lowest 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. |
Requires |
Arguments must be variable of scalar type (i.e. Arithmetic Types and Pointers). |
Example |
d = 0x1AC30F4; tmp = Hi(d); // Equals 0x30 |
Higher
Prototype |
unsigned short Higher(long number); |
---|---|
Returns |
Returns next to the highest byte of |
Description |
Function returns next to the 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. |
Requires |
Arguments must be variable of scalar type (i.e. Arithmetic Types and Pointers). |
Example |
d = 0x1AC30F4; tmp = Higher(d); // Equals 0xAC |
Highest
Prototype |
unsigned short Highest(long number); |
---|---|
Returns |
Returns the highest byte of |
Description |
Function returns the 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. |
Requires |
Arguments must be variable of scalar type (i.e. Arithmetic Types and Pointers). |
Example |
d = 0x1AC30F4; tmp = Highest(d); // Equals 0x01 |
Delay_us
Prototype |
void Delay_us(const unsigned long time_in_us); |
---|---|
Returns |
Nothing. |
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. |
Requires |
Nothing. |
Example |
Delay_us(1000); /* One millisecond pause */ |
Delay_ms
Prototype |
void Delay_ms(const unsigned long time_in_ms); |
---|---|
Returns |
Nothing. |
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. |
Requires |
Nothing. |
Example |
Delay_ms(1000); /* One second pause */ |
Vdelay_ms
Prototype |
void Vdelay_ms(unsigned time_in_ms); |
---|---|
Returns |
Nothing. |
Description |
Creates a software delay in duration of Note that |
Requires |
Nothing. |
Example |
pause = 1000; // ... Vdelay_ms(pause); // ~ one second pause |
Delay_Cyc
Prototype |
void Delay_Cyc(char Cycles_div_by_10); |
---|---|
Returns |
Nothing. |
Description |
Creates a delay based on MCU clock. Delay lasts for 10 times the input parameter in MCU cycles. Note that |
Requires |
Nothing. |
Example |
Delay_Cyc(10); /* Hundred MCU cycles pause */ |
Clock_kHz
Prototype |
unsigned Clock_kHz(void); |
---|---|
Returns |
Device clock in kHz, rounded to the nearest integer. |
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. |
Requires |
Nothing. |
Example |
clk = Clock_kHz(); |
Clock_MHz
Prototype |
unsigned short Clock_MHz(void); |
---|---|
Returns |
Device clock in MHz, rounded to the nearest integer. |
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. |
Requires |
Nothing. |
Example |
clk = Clock_MHz(); |
Get_Fosc_kHz
Prototype |
unsigned long Get_Fosc_kHz(void); |
---|---|
Returns |
Device clock in kHz, rounded to the nearest integer. |
Description |
Function returns device clock in kHz, rounded to the nearest integer. Note that |
Requires |
Nothing. |
Example |
clk = Get_Fosc_kHz(); |
What do you think about this topic ? Send us feedback!