bit, sfr 과 push/pop 사용법

기술노트 40085

아키텍처:

8051

컴포넌트:

compiler

업데이트:

2018-02-28 오전 1:46

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.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.