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

same variable for two different

Hi All,

I have a IIC routine file i2c.asm,which has routines to read and write into a IIC device.

Now I am using the i2c.asm for two devices RTC and serial memory which are connected on different pins.

Question:
---------
How to use the same routines (read & write) to send signals on different pins,right now I am trying to use "SDA set p3.1" and changing the addrs of the sda and scl pin each time before accessing different device ,but it doesnt seem to work.

Is there any other way to get around this problem...

Rgds
Raj Shetgar

Parents Reply Children
  • The simple solution would be two pieces of wire jumping the two IIC ports. Keep one set permanently programmed a '1' which will convert them to 'parallel pullup resistors'.

    Erik

  • Hi Erik,

    Thanx for the suggestion,I'll save this one for the nth moment.

    After reading few replies and documents,I feel that I can use the "SET" assembler directive to solve this but in what ever way I try there is an error message poping up...

    Rgds
    Raj Shetgar

  • After reading few replies and documents,I feel that I can use the "SET" assembler directive to solve this
    No, you can't. You can gandle SCL on 2 pins in software (or Two_pins and and !Two_pins instead of sbit) but the data has to be synchronous.

    Erik

  • In that case, you'll have to roll up your sleeves and start to actually do some work. As in: look sharply at that i2c.asm you grabbed from wherever, and find out how it works. Don't be surprised if this step takes a whole day.

    Find out how the choice of pins used for the I2C protocol is hardwired into the routines. Next, find a way to replace that hardwired set of pins with one you can select at run-time, passing an argument to those routines in some previously unused register, or a global variable. You choose. Given there's no such thing as a "pointer to a port bit" in 8051 machine language, this will be surprisingly hard to do. You need jump tables, or self-modifying code

    The blunt and wasteful way of doing this would be to duplicate the whole code module, changing all symbol names to avoid collisions.

  • Hi Hans,

    I dont understand from where you got the impression that I grabbed the i2c.asm file"grabbed from wherever"...

    Anyways as you suggested I went through the code and It dindt take the whole day since I myself had written this long back.

    I understood why I cant use the "SET" directive.And as you suggested the two different ways to solve this,I used jump tables since the MCS-51 uC I am using doesnt support IAP.

    Thanx a lot...problem solved :-)

    Rgds
    Raj

  • I dont understand from where you got the impression that I grabbed the i2c.asm file"grabbed from wherever"...

    Mainly from the fact tha you only mentioned you "have this module", but didn't appear to understand how it works. That's typical for people grabbing source code from the internet, but without the necessary background knowledge to understand it.

    Anyways as you suggested I went through the code and It dindt take the whole day since I myself had written this long back.

    Well, you just found out that taking source code from your own younger self can be every bit as hard as grabbing from a third party.