I am working one lcd 16x2 en en 4 bits. I read already different information about this.
I am working with one Mcu JM60. with a pll to 40 Mhz I have a problem, because when I have programed the Mcu appear this symbol ← one arrow to the left
I think the problem is in the funcion busy but I do not sure. if anybody can help me I thanks.
the others funtions I am sure are corrects but I doubt of the busy funtion.
void busy()
{
unsigned char bf=1;
//port of dates input
PTEDD_PTEDD7=0;
PTEDD_PTEDD6=0;
PTEDD_PTEDD5=0;
PTEDD_PTEDD4=0;
rs=control; //0
rw=lee; //1
// enable = on;
while (bf ){ // If Busy (PTA7=1), loop
enable = on; // Set E=1
bf = PTED_PTED7; // Read status register
enable = off; // Set E=0
enable = on; // Set E=1
enable = off; // Set E=0
}
PTEDD_PTEDD7=1;
PTEDD_PTEDD6=1;
PTEDD_PTEDD5=1;
PTEDD_PTEDD4=1;
}
Solved! Go to Solution.
Hello,
Your busy() function is probably operational, but I have the following comments -
With a bus frequency of 20MHz, the following sequence may be borderline with respect to the minimum display module timing specification for the E-signal. You may wish to place a small delay between each of the statements. However, I doubt that this will prove to be your problem.
enable = off; // Set E=0
enable = on; // Set E=1
enable = off; // Set E=0
This would become ...
#define DELAY3 __asm nop; __asm nop; __asm nop // Delay 3 cycles
...
enable = off; // Set E=0
DELAY3;
enable = on; // Set E=1
DELAY3;
enable = off; // Set E=0
It is probably a good idea to restore write mode before the function exits, since further operations will generally require write mode. With the present code, it would be problematic if the other LCD functions did not firstly select write mode.
Note that the busy flag is not operative during the first part of the LCD initialization process, with the consequence that you will need to generate time delays here, rather than use the busy flag. If you happen to be attempting to use the busy flag, the initialisation will fail.
Once initialization is complete, the minimum delay requirement following most commands is 40 microseconds, which is not too onerous to provide, in lieu of the testing of the busy flag. Most LCD implementations that I have seen do not bother with the busy flag, but adopt adequate time delays.
I have some additional comments about your code implementation - these are not "errors" per se, but will result in code that isless efficient and is cluttered.
PTEDD_PTEDD7=0;
PTEDD_PTEDD6=0;
PTEDD_PTEDD5=0;
PTEDD_PTEDD4=0;
This is an inefficient coding practice to clear the upper nybble of the data direction register. It is better to do all bits simultaneously using a bit mask.
#define DMASK 0xF0
...
PTEDD &= ~DMASK;
Conversely, to set the upper nybble, you would use -
PTEDD |= DMASK;
In this instance, the busy flag test would be better done using a do...while loop, rather than the existing while loop.
Regards,
Mac
Hello,
Your busy() function is probably operational, but I have the following comments -
With a bus frequency of 20MHz, the following sequence may be borderline with respect to the minimum display module timing specification for the E-signal. You may wish to place a small delay between each of the statements. However, I doubt that this will prove to be your problem.
enable = off; // Set E=0
enable = on; // Set E=1
enable = off; // Set E=0
This would become ...
#define DELAY3 __asm nop; __asm nop; __asm nop // Delay 3 cycles
...
enable = off; // Set E=0
DELAY3;
enable = on; // Set E=1
DELAY3;
enable = off; // Set E=0
It is probably a good idea to restore write mode before the function exits, since further operations will generally require write mode. With the present code, it would be problematic if the other LCD functions did not firstly select write mode.
Note that the busy flag is not operative during the first part of the LCD initialization process, with the consequence that you will need to generate time delays here, rather than use the busy flag. If you happen to be attempting to use the busy flag, the initialisation will fail.
Once initialization is complete, the minimum delay requirement following most commands is 40 microseconds, which is not too onerous to provide, in lieu of the testing of the busy flag. Most LCD implementations that I have seen do not bother with the busy flag, but adopt adequate time delays.
I have some additional comments about your code implementation - these are not "errors" per se, but will result in code that isless efficient and is cluttered.
PTEDD_PTEDD7=0;
PTEDD_PTEDD6=0;
PTEDD_PTEDD5=0;
PTEDD_PTEDD4=0;
This is an inefficient coding practice to clear the upper nybble of the data direction register. It is better to do all bits simultaneously using a bit mask.
#define DMASK 0xF0
...
PTEDD &= ~DMASK;
Conversely, to set the upper nybble, you would use -
PTEDD |= DMASK;
In this instance, the busy flag test would be better done using a do...while loop, rather than the existing while loop.
Regards,
Mac
Thanks
Now it work.