BASIC C SYNTAX DIFFERENCES
PORTING KEIL C51 → SDCC C

HOME
How to convert Keil C51 sources to SDCC C source code format!
This relates to MCS51 aka 8051 MCU architecture specific features.

SFR and BIT Addresses:

sfr P0 = 0x80;__sfr __at (0x80) P0;
sbit P00 = P0 ^ 0;__sbit __at (0x80) P00;

Address Spaces:

   data__data
   xdata__xdata
   idata__idata
   pdata__pdata
   code__code
   bit__bit   addressable bit
   sbit __sbit   specific bit
   sfr__sfr   byte
   sfr16__sfr16   a set
   sfr32__sfr32   a set
Space __bit is also a data type so don't
double declare __bit on the same symbol.

Data Type BIT:

typedef bit Bool;typedef __bit Bool;
Type __bit is also an address space so don't
double declare __bit on the same symbol.

Interrupt declaration:

void uart_isr (void) interrupt 4 using 1   →
void uart_isr (void) __interrupt (4) __using (1)

Keil intrins.h is unavailable in SDCC so for:

To invoke an 8051 no-operation (nop) instruction:
#define nop _nop_ ();#define nop __asm__ ("NOP" );

To invoke an 8051 atomic JBC instruction:
a_flag=_testbit_(a_bit); → one of the following:
   either this:
if (a_bit) { a_bit=0; a_flag=1; } else a_flag=0
   or this:
 #define _testbit_(a_bit) ((a_bit)?(a_bit=0),1:0)
         a_flag=((a_bit)?(a_bit=0),1:0)

But there are many more intrinsic function types defined inside intrins.h
#pragma SAVE
#if defined (__CX2__)
#pragma FUNCTIONS(STATIC)
// intrinsic functions are reentrant but need static attribute
#endif
extern void          _nop_     (void);
extern bit           _testbit_ (bit);
extern unsigned char _cror_    (unsigned char, unsigned char);
extern unsigned int  _iror_    (unsigned int,  unsigned char);
extern unsigned long _lror_    (unsigned long, unsigned char);
extern unsigned char _crol_    (unsigned char, unsigned char);
extern unsigned int  _irol_    (unsigned int,  unsigned char);
extern unsigned long _lrol_    (unsigned long, unsigned char);
extern unsigned char _chkfloat_(float);
#if defined (__CX2__)
extern int           abs       (int);
extern void          _illop_   (void);
#endif
#if !defined (__CX2__)
extern void          _push_    (unsigned char _sfr);
extern void          _pop_     (unsigned char _sfr);
#endif
#pragma RESTORE

Download MCU Headers:

SDCC Headers for all Nuvoton MCUs.zip
SDCC Headers for all STC MUCs.zip

Download Example Code:

Led Blink example for N76E003 in SDCC C.zip

Safety, accuracy and completeness of information provided herein is not guaranteed,
so be inspired by it but do not use it as a basis for experimentation or other actions.

Clickable link!  TOP  ©™
 HOME 
Valid HTML & CSS!
Congrenation.com 2024-12-21T16:02:02.547Z
Version 20231217