PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
io_MCP23X17.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef IO_MCP23X17
27#define IO_MCP23X17
28
29#include "bitbang_i2c.h"
30#include "bitbang_spi.h"
31
32/*
33 pinout
341 GPB0
352 GPB1
363 GPB2
374 GPB3
385 GPB4
396 GPB5
407 GPB6
418 GPB7
429 VDD
4310 VSS
4411 NC - /CS
4512 SCK - SCK
4612 SDA - SI
4714 NC - SO
48
4915 A0
5016 A1
5117 A2
5218 /RESET
5319 INTB
5420 INTA
5521 GPA0
5622 GPA1
5723 GPA2
5824 GPA3
5925 GPA4
6026 GPA5
6127 GPA6
6228 GPA7
63 */
64
65// BANK 0 addr
66#define IODIRA 0x00
67#define IODIRB 0x01
68#define IPOLA 0x02
69#define IPOLB 0x03
70#define GPINTENA 0x04
71#define GPINTENB 0x05
72#define DEFVALA 0x06
73#define DEFVALB 0x07
74#define INTCONA 0x08
75#define INTCONB 0x09
76#define IOCON 0x0A
77#define IOCON_ 0x0B
78#define GPPUA 0x0C
79#define GPPUB 0x0D
80#define INTFA 0x0E
81#define INTFB 0x0F
82#define INTCAPA 0x10
83#define INTCAPB 0x11
84#define GPIOA 0x12
85#define GPIOB 0x13
86#define OLATA 0x14
87#define OLATB 0x15
88
89typedef struct {
90 unsigned char regs[22];
91 unsigned char reg_addr;
92 unsigned char op;
93 unsigned char addr;
94 unsigned char so_active; // serial out pin
95 unsigned char inta_value;
96 unsigned char intb_value;
97 bitbang_spi_t bb_spi;
98 bitbang_i2c_t bb_i2c;
100
101void io_MCP23X17_rst(io_MCP23X17_t* mcp);
102void io_MCP23X17_init(io_MCP23X17_t* mcp);
103void io_MCP23X17_set_addr(io_MCP23X17_t* mcp, unsigned char addr);
104void io_MCP23X17_set_inputs(io_MCP23X17_t* mcp, unsigned char porta, unsigned char portb);
105
106unsigned char io_MCP23X17_SPI_io(io_MCP23X17_t* mcp, unsigned char si, unsigned char sck, unsigned char rst,
107 unsigned char cs);
108unsigned char io_MCP23X17_I2C_io(io_MCP23X17_t* mcp, unsigned char scl, unsigned char sda);
109
110#endif // IO_MCP23X17
Definition bitbang_i2c.h:39
Definition bitbang_spi.h:35
Definition io_MCP23X17.h:89