hey,
thanks for the reply....
1.You can output byte1/byte2 to a port and check if the data is correctly read.
i have already tried displaying the byte1/byte2 values in my 16x2 LCD Module but it does not display anything, no ouput
(rest assured that my LCD is working fine.)
2.One more point is that since you have only ten switches, in one of the bytes, only two bits of infomation will be present and if other bits are read as high......
this is not the case for my MAX7318 for the switches...since it has TWO bytes, i used 5 out of 8 bits of the FIRST byte, and another 5 out of 8 bits of the SECOND byte, making it 10 bits for the 2 bytes ( 5 bits each byte).
3. How is your LED connected, does it turn on with a low bit or a high bit?
the LEDs are turned ON with a high bit. the switch press is supposed to send a low bit to the LED to turn it OFF.
4. while ( (byte1!=0x00) & (byte2!=0x00) ); here logical double AND (&&) should be used.
i have already modified the code according to this...but nothing happens...
with my posted code, the i2c routine is divided into two sections. BOTH sections, however, are talking to the MAX7318, only that the FIRST one is talking to the SWITCH (waiting for a press) and the SECOND section is talking to the LEDs (to be turned off when a press is detected). both sections use a separate MAX7318 but in a different application.
FIRST i2c SECTION:
here, the MAX7318 of the SWITCHES (with the address of 0xA0) are on a READ MODE, MAX7318 waits for a switch press and the data will be saved in byte1 and byte2, which will be fed to the MAX7318 of the LEDs in the second section of the program.
Code:
i2c_start();
i2c_write(0XA0);
i2c_write(0x02);
i2c_start(); //START READING REGISTER
i2c_write(0XA1); //0XA1 = IN READ MODE
byte1=i2c_read(1); //if switch1 is pressed,byte1=0111 1111
byte2=i2c_read(); //READ 2ND BYTE
i2c_read(0); //STOP READING
i2c_stop();
this is the second section:
here, i2c is talking to the MAX7318 of the LEDs (with the address of 0x32) and dictates which LEDs are to be turned off, based on the value of byte1 and byte2.
Code:
i2c_start();
i2c_write(0X32); //UPDATE LEDs WITH SWITCH STATE
i2c_write(0x02); //ACCESS OUTPUT REGISTER
i2c_write(byte1); //WRITE BYTE1 (FROM READ MODE) TO LED
i2c_write(byte2); //WRITE BYTE2 (FROM READ MODE) TO LED
i2c_stop();