aliyesami
Full Member level 6
- Joined
- Jan 7, 2010
- Messages
- 369
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- USA
- Activity points
- 4,190
my 8 bit LCD is working without issues so i am trying now to goto 4 bit mode to save pins.
its giving me headaches . after reading many posts online i modified the LCD busy routine as follows , where am i going wrong?
this code for 8 bit works fine !
the following change I made for 4 bit which is not working I think.
these routines work fine for 8 bit mode!
these routines I modified for 4 bit
its giving me headaches . after reading many posts online i modified the LCD busy routine as follows , where am i going wrong?
this code for 8 bit works fine !
Code:
void Check_LCD_Busy()
{
DataDir_LCD_data = 0;
LCD_controls |= 1<<ReadWrite;
LCD_controls &= ~1<<RS;
while (LCD_data >= 0x80)
{
strobe_enable();
}
DataDir_LCD_data = 0xFF;
}
void strobe_enable()
{
LCD_controls |= 1<<Enable;
_delay_us(50);
LCD_controls &= ~1<<Enable;
}
the following change I made for 4 bit which is not working I think.
Code:
void Check_LCD_Busy()
{
unsigned char portbyte;
DataDir_LCD_data = 0;
LCD_controls |= 1<<ReadWrite;
LCD_controls &= ~1<<RS;
while (LCD_data >= 0x80)
{
strobe_enable();
portbyte = LCD_data;
portbyte = ((LCD_data << 4) & 0xF0); //shift the nibble to MSB
strobe_enable();
portbyte |= (LCD_data & 0x0F); // get the low nibble
LCD_data = portbyte;
}
DataDir_LCD_data = 0xFF;
}
these routines work fine for 8 bit mode!
Code:
void Send_A_Command(unsigned char command)
{
Check_LCD_Busy();
LCD_data = command;
LCD_controls &= ~ ((1<<ReadWrite)|(1<<RS));
strobe_enable();
LCD_data = 0;
}
void Send_A_Character(unsigned char character)
{
Check_LCD_Busy();
LCD_data = character;
LCD_controls &= ~ (1<<ReadWrite);
LCD_controls |= 1<<RS;
strobe_enable();
LCD_data = 0;
}
these routines I modified for 4 bit
Code:
void Send_A_Command(unsigned char command)
{
Check_LCD_Busy();
LCD_data = ((command << 4) & 0xF0); // send high nibble first
LCD_controls &= ~ ((1<<ReadWrite)|(1<<RS));
strobe_enable();
LCD_data = (command & 0b00001111) ; // send low nibble first
LCD_controls &= ~ ((1<<ReadWrite)|(1<<RS));
strobe_enable();
LCD_data = 0;
}
void Send_A_Character(unsigned char character)
{
Check_LCD_Busy();
LCD_data = ((character >> 4) & 0x0F) ; //send high nibble first
LCD_controls &= ~ (1<<ReadWrite);
LCD_controls |= 1<<RS;
strobe_enable();
LCD_data = (character & 0b00001111) ; //send low nibble next
LCD_controls &= ~ (1<<ReadWrite);
LCD_controls |= 1<<RS;
strobe_enable();
LCD_data = 0;
}