Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD and C programming

Status
Not open for further replies.

Makaram

Member
Hi, Got my LCD all up and running now trying to fully understand the whole thing.
I understand in the datasheet it has all the commands etc I'm wondering about this command

LCD_PORT = ch >> 4 & 0xf;

say ch = 0x20

0b00100000 becomes 0b00000010 AND 0b00001111 so because only the 1 bit is high the final outcome is 0b00000010???

would
For(int i=0; i <5; i++)
{
ch >> 1 & 0xf

}

simulate the process or does it jus jump four shifts instantly?
thanks


Thanks,
(special thanks to Nigel, for the code)

Matt
 
Last edited:
void LCD_cmd(unsigned char ch)
{
LCD_PORT = ch >> 4 & 0xf;
LCD_RS = 0;
pulse_E();
LCD_PORT = ch & 0xf;
LCD_RS = 0;
pulse_E();
__delay_ms(5);
}


What is the purpose behind shifting right for every command? why not jus change the input?
 
The character is 8 bits long.... the port is 4 bits long... you MUST sent the high nibble first... The first line shifts the top 4 bits into the LCD_PORT, (the & 0xf; isn't really needed in this instance its just to keep up protocol, protecting the top half of the LCD_PORT) any way the second nibble doesn't need shifting as it's the low anyway (PS.. ch isn't changed during this process).

The loop you have produced would work aswell.. as long as you remove the and mask, and place it at the end of the process.

Sorry... one other thing " ch>>4 & 0xf; " the shift is done first.. THEN the mask is applied.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top