Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing LCD with Atmega32

Status
Not open for further replies.

freddyp007

Junior Member level 2
Joined
Jul 6, 2009
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Freiburg
Activity points
1,417
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?
 

There should be a set of defines of the port pins to LCD data pins , the hardware connection should be the same as defined in the code or the bytes send will be wrong.
There is no problem to connect any pin order to the data lines (even from different ports) as long as you have taken care of the pin assignment so that bits are send to the correct data lines.
You can 't just invert the data lines without making the appropriate changes in your code, it will not work.

Alex
 
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?

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'));

Now if you are sending data in string format, like: PrintLCD("Hello world!");
then you should again have no problem, because PrintLCD() would call LcdSendCharacter() for each sending character of the "Hello world" string. 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.

PS: LcdSendCharacter() and PrintLCD() are random names, I guess that you are already using those routines with names of your own.

Hope this helps.
 
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'));

And what about the LCD commands, how will they be inverted?

Alex

---------- Post added at 02:00 ---------- Previous post was at 01:56 ----------

And by the way, if you need an reverse byte function try the following


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]);
}



It uses a lookup table so it is very fast

Alex
 
alexan_e said:
And what about the LCD commands, how will they be inverted?

The same way:

Code:
LcdSendCommand(reverse(_DISPLAY_CLEAR));

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.
Reverse the port bits directly inside LcdSendCommand() also.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top