freddyp007
Junior Member level 2
What will happen if i connect the data pins of the LCD (D0 to D7) to an atmega port in the reverse order (P7 to P0). Can i display my desired text?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
freddyp007 said:What will happen if i connect the data pins of the LCD (D0 to D7) to an atmega port in the reverse order (P7 to P0). Can i display my desired text?
unsigned char reverse(unsigned char b)
{
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
Just reverse the order of the bits of the sending character and it should work fine.
Code:unsigned char reverse(unsigned char b) { b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; b = (b & 0xCC) >> 2 | (b & 0x33) << 2; b = (b & 0xAA) >> 1 | (b & 0x55) << 1; return b; }
So instead of writing: LcdSendCharacter('A');
you will write: LcdSendCharacter(reverse('A'));
Code C - [expand] 1 2 3 4 5 6 7 /* reverse an 8 bit value, 11000000 ->00000011 */ unsigned char reverse_byte (unsigned char input_byte) { const unsigned char lookup[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; // depending on the compiler use the proper keyword to make this a flash (ROM) variable return (lookup[input_byte & 15]<<4) | (lookup[input_byte>>4]); }
alexan_e said:And what about the LCD commands, how will they be inverted?
LcdSendCommand(reverse(_DISPLAY_CLEAR));
Reverse the port bits directly inside LcdSendCommand() also.Another way is to reverse the port bits directly using the reverse() function before sending them (inside LcdSendCharacter() routine), and now that I think of it this is better because you don't have to change anything in the rest of the code.