I program an 8051 controller which is embedded in an ASIC. Several functions of the ASIC can be controlled by writing to the 8501's ports, but reading the same ports leads to different functions of the ASIC. E.g. writing to P0 controls an oscillator whereas i get a temperature value by reading P0. Is there a proper way to assign two names to a port for either read - or write access and is there a possiblity to prevent programmers from accessing those the wrong way? Thanks for your help! Tobias
one way I can think of is to remove the traditional port definitions and then create a couple of macros SET_FREQ and READ_TEMP that both use absolute port and bit addresses. Erik
I'd go a step higher up and create functions like OscillatorControl (); TemperatureGet (); The implementation of these routines can do the right thing at the right addresses, and higher level code doesn't even need to know how the temperature is actually obtained or the oscillator is controlled.
Thanks for your answers. I didn't write that in my post, but i've got four ports and many of such parameters, most of them even attached to just one bit of a port. Therefore and also because i'm quite limited regarding code space, i don't want to define many functions or macros. Thanks for any further help! Tobias
because i'm quite limited regarding code space, i don't want to define many functions or macros a macro does not increase code space usage. Erik
As Erik points out, macros probably won't increase code space per sec. Look at the absacc.h in the INC folder for some addressing macros that you can copy and modify for your use.