 | Discussion Forum |  |
|
|
doubts using sfrNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Pradheep Shrinivasan Posted 19-Nov-2006 20:36 GMT Toolset C51 |  doubts using sfr Pradheep Shrinivasan hi i wanted to create a genric function led_on(sfr) so that i can use it in at any part of the program as i wish .but i am not able to do it because when i pass the sfr the results are not as expected. i read that sfr cannot be indirectly addressed.what are the other methods to do so. this is my code.
#include "Main.H"
//macros
#define LedOff (bit) 0
#define LedOn (bit) 1
//function prototype
void Led_On(tByte);
//special function registers
sbit Port_Led = P1^7;
void main()
{
Led_On(Port_Led);
while(1);
}
//function to turn on the led
void Led_On(tByte LEDPORT)
{
LEDPORT =LedOn;
}
how do i modify the code?please help
| | Read-Only Author Jon Ward Posted 20-Nov-2006 00:16 GMT Toolset C51 |  RE: doubts using sfr Jon Ward http://www.keil.com/support/docs/185.htm Jon | | Read-Only Author Joost Leeuwesteijn Posted 20-Nov-2006 08:44 GMT Toolset C51 |  RE: doubts using sfr Joost Leeuwesteijn Maybe you could create a separate LED driver module and only use "logical" LED's in your code? pseudo:
led.h:
------
typdef enum { LED1, LED2, etc } tLEDs;
void Led_On(tLEDs ledID, onOff);
led.c:
------
define SFR's here, not publicly available
void Led_On(enum ledID, onOff)
{
switch (ledID)
{
use SFR's to switch each LED
}
}
This way your application does not have to know anything about the underlying hardware and you don't have to pass SFR's. All hardware related things are in the driver. Makes it easier to modify the driver without having to change anything in the rest of the app. Regards, Joost Leeuwesteijn | | Read-Only Author Andy Neil Posted 21-Nov-2006 08:32 GMT Toolset C51 |  RE: doubts using sfr Andy Neil "i wanted to create a genric function led_on(sfr) so that i can use it in at any part of the program as i wish" (my emphasis) Note that there is nothing to stop you from writing directly to SFRs from any point in your program - so there is no need for this from that point of view If your concern is simply to "hide" the underlying hardware implementation, you could do this with macros; eg,
#define LED_ON( LEDPORT ) LEDPORT=LedOn
| |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|