|
|
View previous topic :: View next topic |
Author |
Message |
daniele_hsf
Joined: 08 Jul 2010 Posts: 2
|
MAX 7310 with I2C Expander __pic18f4680 |
Posted: Thu Jul 08, 2010 5:58 am |
|
|
Hi all,
wanted to know if anyone has a library available for the case already made for MAX 7310 2-Wire-Interfaced 8-Bit I/O Port Expander
happy for your response
i waiting ^_^ _________________ che il CCS sia con me XD |
|
|
daniele_hsf
Joined: 08 Jul 2010 Posts: 2
|
|
Posted: Fri Jul 09, 2010 3:00 am |
|
|
HELP ME _________________ che il CCS sia con me XD |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 09, 2010 2:11 pm |
|
|
Here is a simple Max7310 driver that will probably work. I don't have
a Max7310 to test. I just read the data sheet and wrote a driver from
that.
The following program should blink an LED on i/o pin 0 of the Max7310.
You must make the following connections to the Max7310.
1. Connect the Reset pin to +5v.
2. Connect pins AD0, AD1, AD2 to ground.
3. Connect pin SDA to the SDA pin on the PIC.
4. Connect pin SCL to the SCL pin on the PIC.
5. Put 4.7K pull-up resistors on the SDA and SCL lines.
6. Connect +5v to the V+ pin.
7. Connect ground to the GND pin.
8. Connect a series resistor and an LED to the "i/o 1" pin (pin #7)
as shown in the schematic below:
Code: |
pin 330 ohms LED
i/o 1 ---/\/\/\/------->|----
|
|
----- Ground
---
-
|
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
// These are the Max7310 slave addresses with
// pins AD0, AD1, AD2 connected to ground.
// These are pins 3,4,5 on the Max7310 chip.
#define MAX7300_WRITE_ADDR 0x30
#define MAX7300_READ_ADDR 0x31
// Max7310 register addresses.
#define MAX7300_INPUT_REG 0
#define MAX7300_OUTPUT_REG 1
#define MAX7300_POLARITY_REG 2
#define MAX7300_CONFIG_REG 3
#define MAX7300_TIMEOUT_REG 4
//---------------------------------
void max7310_set_config(int8 value)
{
i2c_start();
i2c_write(MAX7300_WRITE_ADDR);
i2c_write(MAX7300_CONFIG_REG);
i2c_write(value);
i2c_stop();
}
//---------------------------------
void max7310_write_port(int8 value)
{
i2c_start();
i2c_write(MAX7300_WRITE_ADDR);
i2c_write(MAX7300_OUTPUT_REG);
i2c_write(value);
i2c_stop();
}
//---------------------------------
int8 max7310_read_port(void)
{
int8 retval;
i2c_start();
i2c_write(MAX7300_WRITE_ADDR);
i2c_write(MAX7300_INPUT_REG);
i2c_start();
i2c_write(MAX7300_READ_ADDR);
retval = i2c_read(0);
i2c_stop();
return(retval);
}
//---------------------------------
void max7310_set_polarity(int8 value)
{
i2c_start();
i2c_write(MAX7300_WRITE_ADDR);
i2c_write(MAX7300_POLARITY_REG);
i2c_write(value);
i2c_stop();
}
//---------------------------------
void max7310_set_timeout(int8 value)
{
i2c_start();
i2c_write(MAX7300_WRITE_ADDR);
i2c_write(MAX7300_TIMEOUT_REG);
i2c_write(value);
i2c_stop();
}
//==========================================
void main()
{
max7310_set_config(0x00); // All outputs
max7310_set_polarity(0x00); // All non-inverted
max7310_set_timeout(0x00); // Disable timeout
// Blink an LED on the "i/o 1" pin of the Max7310 i/o port.
// Note: "i/o 1" is used because "i/o 0" is an Open-Drain pin.
while(1)
{
max7310_write_port(0x02);
delay_ms(500);
max7310_write_port(0x00);
delay_ms(500);
}
}
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|