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 number, bits 7..0.

Description

Function returns the lowest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register.

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 number, bits 8..15.

Description

Function returns next to the lowest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register.

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 number, bits 16..23.

Description

Function returns next to the highest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register.

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 number, bits 24..31.

Description

Function returns the highest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register.

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 time_in_us microseconds (a constant). Range of applicable constants depends on the oscillator frequency.

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 time_in_ms milliseconds (a constant). Range of applicable constants depends on the oscillator frequency.

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 time_in_ms milliseconds (a variable). Generated delay is not as precise as the delay created by Delay_ms.

Note that Vdelay_ms is library function rather than a built-in routine; it is presented in this topic for the sake of convenience.

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 Delay_Cyc is library function rather than a built-in routine; it is presented in this topic for the sake of convenience. There are limitations for Cycles_div_by_10 value. Value Cycles_div_by_10 must be between 2 and 257.

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 Get_Fosc_kHz is library function rather than a built-in routine; it is presented in this topic for the sake of convenience.

Requires

Nothing.

Example
clk = Get_Fosc_kHz();
Copyright (c) 2002-2013 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code