Flash Led -On/Off Example with MCP23017

Applications, examples, and sample programs using products from Comfile Technology

Flash Led -On/Off Example with MCP23017

Postby LESTROSO » Wed Mar 27, 2013 5:26 am

Hi to everybody, here i have enclosed a little program to turn on and off leds of two MCP23017 to adress 010000000 and 010001110 . I hope this help....Best regards,

Lestroso :D
http://www.fasasoftware.com



Code: Select all
    ' Test leds program for MCP23017 By FasaSoftware
    ' www.fasasoftware.com
    ' Flash Leds Output on MCP ADRESS MCP TO 000 port gpio a-b and ADRESS MCP  TO 111 port gpio a-b
    Const Device = CB220
   

    Set I2c 9,8

    ' Register Definitions (Bank = 0)
    #define IODIRA    0x00
    #define IODIRB    0x01
    #define IOPOLA    0x02
    #define IOPOLB    0x03
    #define GPINTENA    0x04
    #define GPINTENB    0x05
    #define DEFVALA    0x06
    #define DEFVALB   0x07
    #define INTCONA    0x08
    #define INTCONB   0x09
    #define IOCONA      0x0A
    #define IOCONB      0x0B
    #define GPPUA      0x0C
    #define GPPUB      0x0D
    #define INTFA      0x0E
    #define INTFB      0x0F
    #define INTCAPA   0x10
    #define INTCAPB   0x11
    #define GPIOA      0x12
    #define GPIOB      0x13
    #define OLATA      0x14
    #define OLATB      0x15

    #define MCP_0_write    0b01000000 'ADRESS MCP  TO 000
    #define MCP_1_write    0b01001110 'ADRESS MCP  TO 111
   

    Dim I2cresult As Byte

    ' Set up MCP23017 I/O direction
    I2cstart
    I2cresult = I2cwrite(MCP_0_write) 'WRITE TO ADDRESS MCP 000
    I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
I2cstart
    I2cresult = I2cwrite(MCP_0_write)
    I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
    ' Test output
I2cstart
    I2cresult = I2cwrite(MCP_1_write) 'WRITE TO ADDRESS MCP 111
    I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
I2cstart
    I2cresult = I2cwrite(MCP_1_write)'WRITE TO ADDRESS MCP 111
    I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
   
    Do

 
  Delay 500
 
        I2cstart
      I2cresult = I2cwrite(MCP_0_write)
       I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b0000000) 'set off led
      I2cstop
      
       I2cstart
      I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b0000000)'set off led
       I2cstop
      
     I2cstart
      I2cresult = I2cwrite(MCP_1_write)
      I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b0000000)'set off led
   I2cstop
      
       I2cstart
       I2cresult = I2cwrite(MCP_1_write)
       I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b0000000)'set off led
       I2cstop
      
Delay 500
 
   I2cstart
      I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
   
         I2cstart
       I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOB)
      I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
      
        I2cstart
       I2cresult = I2cwrite(MCP_1_write)
       I2cresult = I2cwrite(GPIOA)
      I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
      
       I2cstart
      I2cresult = I2cwrite(MCP_1_write)
      I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
    Loop



User avatar
LESTROSO
Terminator
 
Posts: 17
Joined: Thu Mar 12, 2009 10:24 am
Location: ITALY

Re: Flash Led -On/Off Example with MCP23017

Postby EarlMcguire » Fri Sep 27, 2013 10:40 am

LESTROSO wrote:Hi to everybody, here i have enclosed a little program to turn on and off led lighting of two MCP23017 to adress 010000000 and 010001110 . I hope this help....Best regards,

Lestroso :D

http://www.fasasoftware.com



Code: Select all
    ' Test leds program for MCP23017 By FasaSoftware
    ' www.fasasoftware.com
    ' Flash Leds Output on MCP ADRESS MCP TO 000 port gpio a-b and ADRESS MCP  TO 111 port gpio a-b
    Const Device = CB220
   

    Set I2c 9,8

    ' Register Definitions (Bank = 0)
    #define IODIRA    0x00
    #define IODIRB    0x01
    #define IOPOLA    0x02
    #define IOPOLB    0x03
    #define GPINTENA    0x04
    #define GPINTENB    0x05
    #define DEFVALA    0x06
    #define DEFVALB   0x07
    #define INTCONA    0x08
    #define INTCONB   0x09
    #define IOCONA      0x0A
    #define IOCONB      0x0B
    #define GPPUA      0x0C
    #define GPPUB      0x0D
    #define INTFA      0x0E
    #define INTFB      0x0F
    #define INTCAPA   0x10
    #define INTCAPB   0x11
    #define GPIOA      0x12
    #define GPIOB      0x13
    #define OLATA      0x14
    #define OLATB      0x15

    #define MCP_0_write    0b01000000 'ADRESS MCP  TO 000
    #define MCP_1_write    0b01001110 'ADRESS MCP  TO 111
   

    Dim I2cresult As Byte

    ' Set up MCP23017 I/O direction
    I2cstart
    I2cresult = I2cwrite(MCP_0_write) 'WRITE TO ADDRESS MCP 000
    I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
I2cstart
    I2cresult = I2cwrite(MCP_0_write)
    I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
    ' Test output
I2cstart
    I2cresult = I2cwrite(MCP_1_write) 'WRITE TO ADDRESS MCP 111
    I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
I2cstart
    I2cresult = I2cwrite(MCP_1_write)'WRITE TO ADDRESS MCP 111
    I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
    I2cresult = I2cwrite(0b00000000) 'Set To Out leds
    I2cstop
   
   
    Do

 
  Delay 500
 
        I2cstart
      I2cresult = I2cwrite(MCP_0_write)
       I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b0000000) 'set off led
      I2cstop
      
       I2cstart
      I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b0000000)'set off led
       I2cstop
      
     I2cstart
      I2cresult = I2cwrite(MCP_1_write)
      I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b0000000)'set off led
   I2cstop
      
       I2cstart
       I2cresult = I2cwrite(MCP_1_write)
       I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b0000000)'set off led
       I2cstop
      
Delay 500
 
   I2cstart
      I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOA)
       I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
   
         I2cstart
       I2cresult = I2cwrite(MCP_0_write)
      I2cresult = I2cwrite(GPIOB)
      I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
      
        I2cstart
       I2cresult = I2cwrite(MCP_1_write)
       I2cresult = I2cwrite(GPIOA)
      I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
      
       I2cstart
      I2cresult = I2cwrite(MCP_1_write)
      I2cresult = I2cwrite(GPIOB)
       I2cresult = I2cwrite(0b11111111)'set on led
      I2cstop
    Loop




Thanks for sharing code..I was searching for it.. I am working on Flash led project and the post will help me
Last edited by EarlMcguire on Sat Sep 28, 2013 10:06 pm, edited 1 time in total.
EarlMcguire
MasterGoo
 
Posts: 1
Joined: Thu Sep 26, 2013 2:29 am

Re: Flash Led -On/Off Example with MCP23017

Postby LESTROSO » Fri Sep 27, 2013 11:37 am

You're welcome EarlMCguire....I hope you will enjoy and work right with it....see also my site if you want...http://www.fasasoftware.com

BEst regards,

Lestroso :wink:
User avatar
LESTROSO
Terminator
 
Posts: 17
Joined: Thu Mar 12, 2009 10:24 am
Location: ITALY


Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron