Masking address bits


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    mister_e, I don't think the statement:
    I2cWRITE blah,blah2,IoExpander[Loop],[SteakBledindePatate] will work as the variable "IoExpander" is not a constant but rather an array. I have tried using this syntax in the past with no success.

    Dave Purola,
    N8NTA

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, interesting, never tried it before... Thanks Dave!

    Anybody else tried that before and got bad results with this ?

    anyways, here's an easy workaround.

    Code:
    IOExpander var byte[7]
    WichIOExpander var byte
    IOExpander[0]=%11110000
    IOExpander[1]=%11110001
    IOExpander[2]=%11110010
    IOExpander[3]=%11110011
    IOExpander[4]=%11110100
    IOExpander[5]=%11110101
    IOExpander[6]=%11110110
    
    For Loop = 0 to 6
        WichIOExpander=IoExpander[Loop]
        I2cWRITE blah,blah2,WichIOExpander,[SteakBledindePatate]
        pause 5
        next
    OR
    Code:
    IOExpander=%11110110
    
    For Loop = 0 to 6
        I2cWRITE blah,blah2,(IOExpander+Loop),[SteakBledindePatate]
        pause 5
        next
    And if it doesn't work..
    Code:
    WichIOExpander var byte
    IOExpander=%11110110
    
    For Loop = 0 to 6
        WichIOExpander=IOExpander+Loop
        I2cWRITE blah,blah2,WichIOExpander,[SteakBledindePatate]
        pause 5
        next
    Sorry, i can't check any of the above where i am right now.
    Last edited by mister_e; - 18th November 2005 at 07:25.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    mister_e, That is the exact work around I tried in the past with no success. It is still using a variable instead of a constant. I do wish any upcomming versions of PBP will fix this problem. I have 6 PCF8574's that I have addressed in succession and thought I would use 1 address and then just offset it in a formula to access the others. The problem is it only accesses the base address. I had to write seprate statements to access the others. I just thought you and others would like to know.. If any other people on this forum have found a workaround I'm all ears....Chears for now....

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Dave, are you serious? You can't use a variable for that field?

    I'm up the creek also then, my project relies heavily on MCP23016 ICs and controlling them within a loop. One easy alternative would be a bunch of IFs:

    IF loop = 0 THEN I2cWRITE blah,blah2,Constant0,[SteakBledindePatate]
    IF loop = 1 THEN I2cWRITE blah,blah2,Constant1,[SteakBledindePatate]
    IF loop = 2 THEN I2cWRITE blah,blah2,Constant2,[SteakBledindePatate]
    IF loop = 3 THEN I2cWRITE blah,blah2,Constant3,[SteakBledindePatate]
    IF loop = 4 THEN I2cWRITE blah,blah2,Constant4,[SteakBledindePatate]
    IF loop = 5 THEN I2cWRITE blah,blah2,Constant5,[SteakBledindePatate]
    IF loop = 6 THEN I2cWRITE blah,blah2,Constant6,[SteakBledindePatate]
    IF loop = 7 THEN I2cWRITE blah,blah2,Constant7,[SteakBledindePatate]

    But I'm not very keen on this idea.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Demon, This is the code I assumed would work:

    UNIT0 CON %01110000 'U5's CONTROL BYTE (PCF8574A) I/O EXPANDER

    ************************************************** ********
    R_WI2CSW:'READ DIGITAL INPUTS FROM or WRITE DIGITAL OUTPUTS TO PCF8574'S
    ************************************************** ********
    SWCNTR = 0
    WHILE SWCNTR < 6
    CONTROL = UNIT0 | (SWCNTR << 1)
    IF READ_WRITE = 0 THEN 'READ INPUT STATUS FROM PCF8574'S
    I2CREAD SDA,SCL,CONTROL,[SWITCHES(SWCNTR)]
    ELSE 'WRITE OUTPUT STATE TO PCF8574'S
    I2CWRITE SDA,SCL,CONTROL,[OUTPUTS(SWCNTR)]
    ENDIF
    SWCNTR = SWCNTR + 1
    WEND
    RETURN

    But it didn't work as explained in my earlyer post. This is what I had to do instead:

    UNIT0 CON %01110000 'U5's CONTROL BYTE (PCF8574A) I/O EXPANDER
    UNIT1 CON %01110010 'U6's CONTROL BYTE (PCF8574A) I/O EXPANDER
    UNIT2 CON %01110100 'U7's CONTROL BYTE (PCF8574A) I/O EXPANDER
    UNIT3 CON %01110110 'U11's CONTROL BYTE (PCF8574A) I/O EXPANDER
    UNIT4 CON %01111000 'U12's CONTROL BYTE (PCF8574A) I/O EXPANDER
    UNIT5 CON %01111010 'U13's CONTROL BYTE (PCF8574A) I/O EXPANDER


    ************************************************** ********
    R_WI2CS:'READ DIGITAL INPUTS FROM or WRITE DIGITAL OUTPUTS TO PCF8574'S
    ************************************************** ********
    IF READ_WRITE = 0 THEN 'READ INPUT STATUS FROM PCF8574'S
    I2CREAD SDA,SCL,UNIT0,[SWITCHES(0)]
    I2CREAD SDA,SCL,UNIT1,[SWITCHES(1)]
    I2CREAD SDA,SCL,UNIT2,[SWITCHES(2)]
    I2CREAD SDA,SCL,UNIT3,[SWITCHES(3)]
    I2CREAD SDA,SCL,UNIT4,[SWITCHES(4)]
    I2CREAD SDA,SCL,UNIT5,[SWITCHES(5)]
    ELSE
    I2CWRITE SDA,SCL,UNIT0,[OUTPUTS(0)]
    I2CWRITE SDA,SCL,UNIT1,[OUTPUTS(1)]
    I2CWRITE SDA,SCL,UNIT2,[OUTPUTS(2)]
    I2CWRITE SDA,SCL,UNIT3,[OUTPUTS(3)]
    I2CWRITE SDA,SCL,UNIT4,[OUTPUTS(4)]
    I2CWRITE SDA,SCL,UNIT5,[OUTPUTS(5)]
    ENDIF
    RETURN

    Now very elegant......

    Dave Purola,
    N8NTA
    Last edited by Demon; - 4th October 2016 at 18:06.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I'll have an eye on this once back in town. Interesting...

    Is the same thing happen with Lookup too?

    Code:
    WichIOExpander var byte
    
    For Loop = 0 to 6
        Lookup WichIOExpander,[%11110000,%11110001,%11110010,%11110011,_
                               %11110100,%11110101,%11110110]
        I2cWRITE blah,blah2,WichIOExpander,[SteakBledindePatate]
        pause 5
        next
    About now? Just curious
    Last edited by mister_e; - 18th November 2005 at 19:18.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Steve, I'm not set up to test right now.

    Dave, are you sure you used a BYTE?

    I reread the manual and there is nothing for I2CREAD that says CONTROL byte must be a constant.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  3. RF Transmitter
    By et_Fong in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2005, 16:34
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31
  5. 18f452 internal eprom help
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 13th July 2004, 15:50

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts