Masking address bits


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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!

  2. #2
    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.

  3. #3
    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.

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


    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!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Dave, here's my complete code using a 16F877 and MCP23016:

    ADCON1 = 7 ' A/D off, all digital
    ASM
    @ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
    ENDASM
    define OSC 20
    DEFINE I2C_SLOW 1 ' Access I2C device above 8MHz
    DEFINE I2C_HOLD 1 ' Permit I2C device to hold clock line low
    I2CSCL VAR PortC.3
    I2CSDA VAR PortC.4
    I2CCTRL con %01000000
    I2CLOCB VAR BYTE
    I2CWORD VAR WORD
    I2CLOCB = $06 ' Set location to IODIR register
    I2CWORD = %0000000000000000
    i2cWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOCB,[I2CWORD]
    PAUSE 12
    I2CLOCB = $00 ' Set location to GPIO register
    I2CWORD = %1111111111111111
    i2cWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOCB,[I2CWORD]
    end

    It doesn't work, and it is using a constant.

    I don't understand why either, I had this circuit working a few weeks ago. I'm sure I have something screwed in the code, but I don't see what it can be.

    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!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Just a bit more on the code above, the 1st I2CWRITE sets the pins as output, the 2nd turns them all ON.
    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