GENERATING A LIBRARY FOR GENERIC DEVICES
Applies to: General Topics
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
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.
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
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.
You may include the assembler module in the library to supply a
default address for the port pins.
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 uVision2
User's Guide, Chapter 4, Creating Projects
Article last edited on: 2005-08-03 10:17:22
Rate this article
Disagree? Move your mouse over the bar and click