Hi, I will use a 4-bit LCD with 8051. But there is a problem, LCD's data pins are connected in reverse order. i.e. D7 to P2^0 D6 to P2^1 D5 to P2^2 D4 to P2^3 My previosly written program uses a port called Data which is defined as #define Data P2 Now i want to simple change the "Data" definition with reversed ordered P2 pins, without changing the program itself. How can i do this?
My previosly written program uses a port called Data which is defined as #define Data P2. Now i want to simple change the "Data" definition with reversed ordered P2 pins, without changing the program itself. How can i do this? ? 1) if "My previosly written program" is actually written (not copied) by you you do not need to ask 2) the only way to do this "without changing the program itself" is by making a new board with the pins in the right order. 3) The change to the program is one that anyone that is actually themselves capable o writing a program to drive a LCD should have no problem whatsoever with. Erik
Hi, I am very sad to hearing these, but may be i must give more information. I am not an expert. Just for a few months, i am dealing with keil c51. I am looking for examples, articles etc. I write this program myself. But i have searched a lot of thing and i study some codes doing this job. Then i combine these and write my own code. But if you mean something different, that every thing in the code is belong to me, that's not. I look for other codes and change them to entegrate my whole code. So, here is the relevant part of the code and definitons:
#define Data P2 sbit EN = P2^4; sbit RS = P2^6; sbit RW = P2^5; void LcdWrite(unsigned char val){ RS = 1; RW = 0; Data &= 0xF0; Data |= val >> 4; EN = 1; EN = 0; Data &= 0xF0; Data |= val & 0x0F; EN = 1; EN = 0; LcdWait(); }
"Now i want to simple change the "Data" definition with reversed ordered P2 pins, without changing the program itself." The program has to change. Looking at the code you posted, the bits are not only reversed, but they have also moved to P2's most-significant nibble. Use a lookup table to reverse and move the nibble's bits:
const unsigned char code reverse[] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0 }; void LcdWrite(unsigned char val){ RS = 1; RW = 0; Data &= 0x0F; Data |= reverse[val >> 4]; EN = 1; EN = 0; Data &= 0x0F; Data |= reverse[val & 0x0F]; EN = 1; EN = 0; LcdWait(); }
Thank you very much, This solved the problem. Actually with a little change it solved the problem. Tha data pins are connected to leas-significant nibble, So i change the code as follows
const unsigned char code reverse[] = { 0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F };
"Tha data pins are connected to leas-significant nibble ..." Yes, of course. Sorry, I don't know what I was thinking. "When i write more than 16 characters without changing the line addres, lcd goes somewhere actually not on lcd, and it passes the second line after 34 character or something like that. Is this normal, or it is a problem with intializing the lcd?" If you are using a common HD44780-controlled display, this is normal with line 2 starting at address 64.
I am not an expert. Just for a few months, i am dealing with keil c51. I am looking for examples, articles etc. I write this program myself. But i have searched a lot of thing and i study some codes doing this job. Then i combine these and write my own code. The danger of using "examples" is that you learn NOTHING!. as I said "anyone who can write a LCD driver should have no problem with this" By using "examples" and sometimes asking here, you can get much mundane stuff to work, but when you get tasked with a real job, you will be blank. Write some code without using "examples" and make it work, you will learn more in less time. Erik