This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

doubts using sfr

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

Parents
  • "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
    

Reply
  • "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
    

Children
No data