View previous topic :: View next topic |
Author |
Message |
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Wed May 07, 2008 7:27 pm |
|
|
it worked!
here is the final code that can successfully display the bytes (in read mode) of MAX7318 in the LCD display.
Code: |
byte setme[5]={0xFE,0xFD,0xFB,0xF7,0xEF};
while(1)
{
see_switch();
printf(lcd_putc,"b1:%Xb2:%X\n",byte1,byte2);
delay_ms(100);
}
void see_switch()
{
i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_start(); //START READING REGISTER
i2c_write(0xA1);
byte1=i2c_read(); //if switch1 is pressed, byte1=1111 1110
byte2=i2c_read(0); //READ 2ND BYTE
i2c_stop();
//however, with the second part of the i2c, (writing to the
//MAX7318 of the LEDs), this is the code that worked (and not
//the previously posted one...)
switch(byte1)
{
case 0xFE:
{i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(setme[0]);
i2c_write(0x00);
i2c_stop();
break;}
case 0xFD:{
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(setme[1]);
i2c_write(0x00);
i2c_stop();
break;}
case 0xFB:{
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(setme[2]);
i2c_write(0x00);
i2c_stop();
break;}
case 0xF7:{
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(setme[3]);
i2c_write(0x00);
i2c_stop();
break;}
case 0xEF:{
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(setme[4]);
i2c_write(0x00);
i2c_stop();
break;}
}
}
|
i don't know what is wrong with the bytes then...so i started thinking of doing it the LONG way ( using array setme[5] ) and it worked. however that would be very impratical with my case because i have 10 switches. the program would be too long and redundant, it won't be a good code, right?...is there any better way to do it?
the LCD ouput displays only FE, FD, FB, F7 and FF...
can someone tell me why is it that i can't feed that value to the MAX7318? and why is it that when i completed these values to be 0XFE, 0XFD, 0xFB, 0xF7, 0xFF.... that's only when everything worked...is this something to do with the BYTE FORMAT? thanks.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 7:54 pm |
|
|
Try this code instead of the switch-case code. It should do the same
thing, and do it with a lot less code:
Quote: |
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(byte1);
i2c_write(0x00);
i2c_stop();
|
|
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Thu May 08, 2008 2:03 am |
|
|
thanks, PCM Programmer....
i already tried that one but it's not working on my case. that would have made things quite easier....i don't know what is wrong but it just won't work.
are there any possible solutions?
thanks again... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 08, 2008 11:30 am |
|
|
The two methods effectively do the same thing. It should work.
The switch-case introduces a small delay before the next i2c operation
begins, but it's only a few microseconds. You could try adding a delay
between the two i2c operations. Example:
Quote: |
i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1);
byte1=i2c_read();
byte2=i2c_read(0);
i2c_stop();
delay_ms(1);
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(byte1);
i2c_write(0x00);
i2c_stop();
|
I don't claim that this will fix it. I'm not sure what the problem is. |
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Fri May 09, 2008 12:22 am |
|
|
by the way, here is the schematic diagram...i hope this link works....
or this one.....
|
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Mon May 12, 2008 7:52 am |
|
|
hello everyone....
here's the final code that works for my MAX7318 Switch and LED application....
Code: |
void see_switch()
{
while ( 1 )
{
i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1);
byte1=i2c_read();
byte2=i2c_read(0);
i2c_stop();
delay_ms(10);
while ( (byte1==~portA) && (byte2==~portB) )
{
i2c_start();
i2c_write(0x32);
i2c_write(0x02);
i2c_write(byte1);
i2c_write(byte2);
i2c_stop();
}
}
} |
the code will not only turn the LED off for a certain time but permanently (unless reset, ofcourse )
problem solved!
thank you everyone for the attention and help....
this is such a great forum...and the first time i made my code work!
thanks! |
|
|
|