What are the C compiler functions for the EFM8 to convert a 16 bit count of Timer0 (TL0 & TH0) to an integer value,

and then after an arithmetic calculation with the integer, re-load Timer0 with a new count for TL0 & TH0?

Furthermore, is there a reference for the SiLabs Keil compiler provided by SiLabs, ANXXX, which defines these types of functions.

Discussion Forums

8-bit MCUs

Answered

Answered

Hi SoCal,

There are some timer0 examples, including 16 bit in Simplicity Studio, for example EFM8BB1_Timer0_16bit. Which EFM8 part are you using?

There aren't any library functions to break a 16 bit variable into two 8 bit registers (and the other way around), but it can be done with bit masking and shifting.

Please let me know if you have any further questions.

Regards,

Joe

0

After posting my question, I developed this:

1. Conversion of two eight bit registers to an integer Y;

Register A (8 bits) & Register B (8bits), where A is the MSByte

Integer Y = A * 256 + B

2. Conversion of Y to two eight bit registers A & B;

Register A (8 bits) & Register B (8 bits), where 0<= Y <= 65535

Register A = int ( Y / 256 ), where Register A is the MSByte

Register B = int (Y ) - 256 * Register A

0

it depends on the configuration of the oscillator type you are using either an external or internal one

0

You could have a look at example for C8051Fxxx example. I think below code may help:

Thanks for the suggestion. As a result, here's a supplement:

1. Conversion of two eight bit registers to an integer Y;
Register A (8 bits) & Register B (8bits), where A is the MSByte
Integer Y = A * 256 + B
Then;
volatile int REGA;
volatile int REGB;
volatile int Y;
REGA = TH0;
REGB = TL0;
Y = REGA * 256 + REGB
2. Conversion of Y to two eight bit registers A & B;
Register A (8 bits) & Register B (8 bits), where 0<= Y <= 65535
Register A = int ( Y / 256 ), where Register A is the MSByte
Register B = int (Y ) - 256 * Register A
Then;
#define TIMER0_RELOAD_HIGH REGA
#define TIMER0_RELOAD_LOW REGB
REGA = int (Y / 256);
REGB = int (Y) - 256 * REGA
TH0= TIMER0_RELOAD_HIGH;
TL0 = TIMER0_RELOAD_LOW;

Surely there's a SiLabs repository for various 8051 compiler functions such as the Timer0 reload noted in this thread.

Obviously this would greatly enhance one's efficiency in coding.

## Timer0 Calculations

What are the C compiler functions for the EFM8 to convert a 16 bit count of Timer0 (TL0 & TH0) to an integer value,

and then after an arithmetic calculation with the integer, re-load Timer0 with a new count for TL0 & TH0?

Furthermore, is there a reference for the SiLabs Keil compiler provided by SiLabs, ANXXX, which defines these types of functions.

Hi SoCal,

There are some timer0 examples, including 16 bit in Simplicity Studio, for example EFM8BB1_Timer0_16bit. Which EFM8 part are you using?

There aren't any library functions to break a 16 bit variable into two 8 bit registers (and the other way around), but it can be done with bit masking and shifting.

Please let me know if you have any further questions.

Regards,

Joe

After posting my question, I developed this:

1. Conversion of two eight bit registers to an integer Y;

Register A (8 bits) & Register B (8bits), where A is the MSByte

Integer Y = A * 256 + B

2. Conversion of Y to two eight bit registers A & B;

Register A (8 bits) & Register B (8 bits), where 0<= Y <= 65535

Register A = int ( Y / 256 ), where Register A is the MSByte

Register B = int (Y ) - 256 * Register A

it depends on the configuration of the oscillator type you are using either an external or internal one

You could have a look at example for C8051Fxxx example. I think below code may help:

C:\SiliconLabs\SimplicityStudio\v5\developer\sdks\8051\v4.2.0\examples\C8051F330DK\Timers\F33x_Timer0_16bitTimer\src

Thanks for the suggestion. As a result, here's a supplement:

1. Conversion of two eight bit registers to an integer Y;

Register A (8 bits) & Register B (8bits), where A is the MSByte

Integer Y = A * 256 + B

Then;

volatile int REGA;

volatile int REGB;

volatile int Y;

REGA = TH0;

REGB = TL0;

Y = REGA * 256 + REGB

2. Conversion of Y to two eight bit registers A & B;

Register A (8 bits) & Register B (8 bits), where 0<= Y <= 65535

Register A = int ( Y / 256 ), where Register A is the MSByte

Register B = int (Y ) - 256 * Register A

Then;

#define TIMER0_RELOAD_HIGH REGA

#define TIMER0_RELOAD_LOW REGB

REGA = int (Y / 256);

REGB = int (Y) - 256 * REGA

TH0= TIMER0_RELOAD_HIGH;

TL0 = TIMER0_RELOAD_LOW;

Surely there's a SiLabs repository for various 8051 compiler functions such as the Timer0 reload noted in this thread.

Obviously this would greatly enhance one's efficiency in coding.