Port alias in Port Expanders (MCP23S17)


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    Thanks I will try that!

    I have made some progress but I still need a way to get from 1 byte which will tell me which of the 16 outputs to turn on.

    Current test code:
    Code:
                          OutA=$FFFE                                        'Initial value for word var                      
                          OutA_hi=OutA.highbyte                             'Splits into hibyte
                          OutA_lo=OutA.lowbyte                              'And into low byte of the word var
                          OutA_lo.3=0                                       'Bit mod
                          OutA_hi.5=0                                       'Another bit mod
                            OutA_MCPReg = OLATA                             'Sets up PORTA output
                            OutA_DataOut=OutA_lo                            'Sets up data to be pushed to the MCP23S17 as the low byte
                            gosub SEND_OutA_2317                            'Send it
                            pause 10                                        'Wait a bit
                            OutA_MCPReg = OLATB                             'Sets up PORTB output
                            OutA_DataOut=OutA_hi                            'Sets up data to be pushed to the MCP23S17 as the hi byte
                            gosub SEND_OutA_2317                            'Send it
    This gives me what I want - EXCEPT - for that I have to resolve 1 byte into a word and figure out how to get the pointer right........
    starting with a byte var which has a value from 0-15 to a specific bit on the MCP23S17 still evades me I am afraid.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    Henrik-
    Thanks for the assist, but I don't think I can use that idea. There are some outputs which will be already active which another serial command comes in and I will need to add to the already ON LEDs with whatever new ones are called for.
    There is a serial comm line coming into the project and on that serial comm is a byte which will let me know which output(s) to turn on. Some may or may not be on.
    So, I will have to logically AND them to get the correct outputs on when they need to be.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    Why does this not work?
    OutA.12=0 doesn't gen an error but it nor the other (OutA.15=0) turns ON an LED?????

    Code:
                          OutA=$FFFE                                        'Initial value for word var                      
                          OutA_hi=OutA.highbyte                             'Splits into hibyte
                          OutA_lo=OutA.lowbyte                              'And into low byte of the word var
    '                      OutA_lo.3=0                                       'Bit mod - WORKS
    '                      OutA_hi.5=0                                       'Another bit mod - WORKS
                          OutA.12=0      'Why doesn't this work?
                          OutA.15=0      'Or this?
                            OutA_MCPReg = OLATA                             'Sets up PORTA output
                            OutA_DataOut=OutA_lo                            'Sets up data to be pushed to the MCP23S17 as the low byte
                            gosub SEND_OutA_2317                            'Send it
                            pause 10                                        'Wait a bit
                            OutA_MCPReg = OLATB                             'Sets up PORTB output
                            OutA_DataOut=OutA_hi                            'Sets up data to be pushed to the MCP23S17 as the hi byte
                            gosub SEND_OutA_2317                            'Send it
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,662


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    OutA_hi=OutA.highbyte 'Splits into hibyte
    OutA_lo=OutA.lowbyte 'And into low byte of the word var
    is a simple assignment operation not an alias

    OutA=$FFFE 'Initial value for word var
    OutA.12=0
    OutA.15=0
    OutA_hi=OutA.highbyte 'Splits into hibyte
    OutA_lo=OutA.lowbyte 'And into low byte of the word var
    would fix it (get the order correct)

  5. #5
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    Thanks!
    I tried your suggestion:
    Code:
                          OutA=$FFFF                                        'Initial value for word var                      
                          OutA.0=0                                       'Bit mod - WORKS
                          OutA.2=0                                       'Another bit mod - WORKS                      OutA.0=0                                       'Bit mod - WORKS
                          OutA.8=0                                       'Another bit mod - WORKS
                          OutA.10=0                                       'Bit mod - WORKS
                          OutA.12=0                                       'Another bit mod - WORKS
                          OutA_hi=OutA.highbyte                             'Splits into hibyte
                          OutA_lo=OutA.lowbyte                              'And into low byte of the word var
                            OutA_MCPReg = OLATA                             'Sets up PORTA output
                            OutA_DataOut=OutA_lo                            'Sets up data to be pushed to the MCP23S17 as the low byte
                            gosub SEND_OutA_2317                            'Send it
                            pause 10                                        'Wait a bit
                            OutA_MCPReg = OLATB                             'Sets up PORTB output
                            OutA_DataOut=OutA_hi                            'Sets up data to be pushed to the MCP23S17 as the hi byte
                            gosub SEND_OutA_2317                            'Send it
    And it works like a CHAMP!
    However (you knew it might come) how do I resolve a single byte variable which tells me which bit to turn on/off into a word var?
    My need for this home project, is to read a byte var and based on its value turn on/off a bit on the expander?
    Example: Var=$C, so I need to turn on the 12th bit on the expander.
    Regards,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  6. #6
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    Richard-
    I tried the following:
    Code:
                          OutA=$FFFF                                        'Initial value for word var                      
                          PortDevice=$D                                     'Var from comm link
                          K=PortDevice                                      'Copes var to var for hex to dec converter
                          gosub H2D                                         'Perform sub
                          OutA.K=0     'PBP3 barks with 'Bad variable modifier
                          OutA.0=0                                          'Bit mod - WORKS
                          OutA.2=0                                          'Another bit mod - WORKS                      OutA.0=0                                       'Bit mod - WORKS
                          OutA.8=0                                          'Another bit mod - WORKS
                          OutA.10=0                                         'Bit mod - WORKS
                          OutA.12=0                                         'Another bit mod - WORKS
                          OutA_hi=OutA.highbyte                             'Splits into hibyte
                          OutA_lo=OutA.lowbyte                              'And into low byte of the word var
                            OutA_MCPReg = OLATA                             'Sets up PORTA output
                            OutA_DataOut=OutA_lo                            'Sets up data to be pushed to the MCP23S17 as the low byte
                            gosub SEND_OutA_2317                            'Send it
                            pause 10                                        'Wait a bit
                            OutA_MCPReg = OLATB                             'Sets up PORTB output
                            OutA_DataOut=OutA_hi                            'Sets up data to be pushed to the MCP23S17 as the hi byte
                            gosub SEND_OutA_2317                            'Send it
    In an effort to get from the single byte to the pointer, but PBP3 barks with the bad variable modifier.......
    There a ought to be a way to do this.......
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  7. #7
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Port alias in Port Expanders (MCP23S17)

    OK, it is working!
    Thanks to all who helped and provided some food for thought.....
    Code below for any others who need to do this:
    Code:
                          OutA=$FFFF                                        'Initial value for word var - everything is OFF                      
                          PortDevice=$A                                     'Var from comm link
                          OutA.0[PortDevice]=0                              'This works!
    '                      OutA.2=0                                          'Manual bit mod - works though  
    '                      OutA.12=0                                         'Manual bit mod - works though
                          OutA_hi=OutA.highbyte                             'Splits into hibyte
                          OutA_lo=OutA.lowbyte                              'And into low byte of the word var
                            OutA_MCPReg = OLATA                             'Sets up PORTA output
                            OutA_DataOut=OutA_lo                            'Sets up data to be pushed to the MCP23S17 as the low byte
                            gosub SEND_OutA_2317                            'Send it
                            pause 10                                        'Wait a bit
                            OutA_MCPReg = OLATB                             'Sets up PORTB output
                            OutA_DataOut=OutA_hi                            'Sets up data to be pushed to the MCP23S17 as the hi byte
                            gosub SEND_OutA_2317                            'Send it
    Happy New Year!
    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

Similar Threads

  1. I2C question w/ MCP23017 Port Expanders
    By dsicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th December 2012, 05:47
  2. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 11:41
  3. LCD R/S works on Port A but not Port B
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th February 2009, 12:41
  4. RB port sequencer
    By freelancebee in forum mel PIC BASIC
    Replies: 0
    Last Post: - 17th August 2005, 19:58
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43

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