Keil Logo


Information in this article applies to:

  • C166 all Versions
  • C251 all Versions
  • C51 all Versions


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.


  • Getting Started with µVision2 User's Guide, Chapter 4, Creating Projects



The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, August 3, 2005

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.