+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Full Member level 1
    Points: 3,015, Level: 12

    Join Date
    Jul 2004
    Location
    Brasov, Romania
    Posts
    105
    Helped
    9 / 9
    Points
    3,015
    Level
    12

    8051 parameters

    Hi all

    Can anyone tell me how to pass sbit and/or sfr addresses as function parameters in Ke*il, so that later on I can assign values to those sbits or sfrs (more specifically port pins, or an entire port).
    I am trying to write a set of LCD functions (HD44780 compatible) and make it a library. Using it as a library, I have to make it flexible to the level that the data port and control pins can be specified by the means of library functions. This is where my problem begins.

    Thanks

    •   AltAdvertisment

        
       

  2. #2
    Member level 4
    Points: 1,882, Level: 10

    Join Date
    Mar 2004
    Location
    Tarnaveni, Romania
    Posts
    71
    Helped
    0 / 0
    Points
    1,882
    Level
    10

    keil + function + sbit

    Hi,

    Use a char variable for SFR, and use AND/OR to handle the bits :)

    Cheers !



    •   AltAdvertisment

        
       

  3. #3
    Full Member level 1
    Points: 2,706, Level: 12

    Join Date
    Sep 2002
    Location
    Germany
    Posts
    118
    Helped
    2 / 2
    Points
    2,706
    Level
    12

    sbit-address 8051

    SFR addresses and bits are not possible as params in Keil
    See also the c51 manual

    usbman



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 4
    Points: 11,875, Level: 26
    bobcat1's Avatar
    Join Date
    Jul 2002
    Posts
    1,288
    Helped
    99 / 99
    Points
    11,875
    Level
    26

    sbit 8051

    Hello

    Here is how to access an SFR using it's address C language

    //Set Ptr to the address - if the SFR lay at address 99H :

    #define sfr_test 0x099 //0x099 is the SFR address

    void ChangeSfr(unsigned char *SfrData)
    {
    //Set the value of the SFR to 55H
    SfrData = 0x55;

    }


    //Function call
    ChangeSfr((unsigned char *)sfr_test);


    I don't think you can use this methode to access a single bit !
    regards

    Bobi



  5. #5
    Newbie level 6
    Points: 1,474, Level: 8

    Join Date
    Jan 2005
    Posts
    13
    Helped
    0 / 0
    Points
    1,474
    Level
    8

    sbit in keil

    to pass bits as function parameters define the bit as an sbit at the beginning of the program and then use the same definition as the function parameter
    e.g:-
    sbit ACC_0=0xE0;
    void a_func(ACC_0)
    {
    }
    This works as long as the function calling is properly defined
    This has been tried and tested in Keil(uvision 2)
    ayan



    •   AltAdvertisment

        
       

  6. #6
    Full Member level 1
    Points: 2,706, Level: 12

    Join Date
    Sep 2002
    Location
    Germany
    Posts
    118
    Helped
    2 / 2
    Points
    2,706
    Level
    12

    passing sfr values in function in 8051

    none of the above soulutions will work
    params are passed in registers! in Keil

    please check the asm output

    usbman



--[[ ]]--