ARM Technical Support Knowledge Articles


Applies to: General Topics


Information in this article applies to:


I want to create a library that can be used for any member of the 8051 (or C16x or 251) family. My library uses SFR bits which are located at different addresses depending on the device that is used.

For example, I need to specify three I/O port bits to use for an LCD device. The port bits are named LCD_DS, LCD_RW, and LCD_EN.

Is there a way to implement a library that is independent of a specific microcontroller device?


Yes, this is possible.

  1. To avoid using chip-specific features, select a standard device for the library project. The devices listed under the Generic vendor in the device database are a good choice.
  2. In your C code, define your I/O port pins as extern bit. Declare the actual I/O port pins (and the address) in an assembler module. Refer to C51: ACCESSING EXTERNAL SFR'S IN A C PROGRAM for an example of how to do this.
  3. You may include the assembler module in the library to supply a default address for the port pins.
  4. In the actual project that includes the library, you may simply add a modified version of the I/O port assembler definition file. Just be sure that this file is added in the project before the library file so that the assembler module from the library will be not link into the final target.



Article last edited on: 2005-08-03 10:17:22

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential