How to use bit, sfr and push/pop intrinsics

Technical Note 40085

Targets:
8051

Component:
Compiler

Updated:
4/2/2009 3:21 PM

Introduction

This Technical Note discusses some issues that occurs for users that are migrating from the Keil tools to IAR Embedded Workbench for 8051.

Examples

The examples are written using IAR Embedded Workbench for 8051 version V7.x (or later).

The examples show how to use bit variables, sfr variables and how to replace the Keil intrinsic functions _push_() and _pop_().

One common question...

...is how you can replace the Keil sbit syntax and the answer is that you simply use our header files instead. In there we use anonymous SFR unions with both a char and a bitfield.

Example 1

#include <stdbool.h>
__no_init bool __bit mybit;

#define BIT __no_init bool __bit
BIT mybit2;

void main(void)
{
mybit = 1;
mybit2 = 1;
}

Example 2

__sfr __no_init volatile unsigned int test_int @0x92;
__sfr __no_init volatile unsigned char test_char @0x94;

#define SFR __sfr __no_init volatile
SFR unsigned int test_int2 @0x96;
SFR unsigned char test_char2 @0x98;

void main(void)
{
test_int = 0x1122;
test_char = 0x33;
test_int2 = 0x4455;
test_char2 = 0x66;
}

Example 3

#define _push_(X) { char __tmp; __tmp=X;
#define _pop_(X) X=__tmp;}

All product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.