Hello, I'm trying to learn about TWI inteface with PCF8574 and testing on Proteus. I want to use 1 PCF8574 as read button status and show it onto 3 pieces 7 segment digits which are connected to 3 pieces PCF8574. My problem is when I press a button then it does not show any result or sometimes show strange values. What can be problem ?
My code and schematic is attached to the message.
#include <Wire.h>
#define ones_pcf8574_addr 0b0100000
#define tens_pcf8574_addr 0b0100001
#define hundreds_pcf8574_addr 0b0100010
#define button_pcf8574_addr 0b0100100
byte seg[10] = {
0b01111110, 0b00110000, 0b01101101, 0b01111001, 0b00110011, 0b01011011,
0b01011111, 0b01110000, 0b01111111, 0b01111011
};
volatile byte _data = 0xff;
boolean hasInt;
byte value = 0;
void extInt() {
hasInt = true;
value++;
}
void setup() {
Wire.begin();
pinMode(8, INPUT);
pinMode(9, OUTPUT);
ones(0);
tens(0);
hundreds(0);
attachInterrupt(0, extInt, FALLING);
}
void loop() {
if(hasInt) {
readData();
hasInt = false;
}
}
void readData() {
//byte _data;
Wire.requestFrom(button_pcf8574_addr, 1);
if (Wire.available()) {
_data = Wire.read();
}
display(_data);
}
void ones(byte val) {
Wire.beginTransmission(ones_pcf8574_addr);
Wire.write(seg[val]);
Wire.endTransmission();
delay(5);
}
void tens(byte val) {
Wire.beginTransmission(tens_pcf8574_addr);
Wire.write(seg[val]);
Wire.endTransmission();
delay(5);
}
void hundreds(byte val) {
Wire.beginTransmission(hundreds_pcf8574_addr);
Wire.write(seg[val]);
Wire.endTransmission();
delay(5);
}
void display(byte val) {
ones(val % 10);
tens(val / 10);
hundreds(val / 100);
}