bsodmike
New Member
Hello guys,
I'm about to start working with a 1x16 LCD and am trying to start somewhere. I'm currently looking at an example included with the PICC-Lite compiler but this code has me quite confused:
First of all the little bit at the top about PORTA*8+2 :shock: Could some one please explain this bit of code, it's quite alien to me.
Strobing: Why can't we just set PORTA, 3 high, then low rather than using this odd code?
Running the LCD in 4bit mode has me confused. From what I can see it takes the '8bit' value, rotates it right 4 times, so you end up sending the lower 4 bits (why the | ?) Then c & 0x0F is that masking off the lower 4 bits such that you only send the top most bits (i.e. bits 0 - 3) which makes up the full 8bits?
Thanks,
Mike
I'm about to start working with a 1x16 LCD and am trying to start somewhere. I'm currently looking at an example included with the PICC-Lite compiler but this code has me quite confused:
Code:
/*
* PORTA bit 2 is connected to the LCD RS input (register select)
* PORTA bit 3 is connected to the LCD EN bit (enable)
*/
static bit LCD_RS @ ((unsigned)&PORTA*8+2); // Register select
static bit LCD_EN @ ((unsigned)&PORTA*8+3); // Enable
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c)
{
PORTB = (PORTB & 0xF0) | (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}
First of all the little bit at the top about PORTA*8+2 :shock: Could some one please explain this bit of code, it's quite alien to me.
Strobing: Why can't we just set PORTA, 3 high, then low rather than using this odd code?
Running the LCD in 4bit mode has me confused. From what I can see it takes the '8bit' value, rotates it right 4 times, so you end up sending the lower 4 bits (why the | ?) Then c & 0x0F is that masking off the lower 4 bits such that you only send the top most bits (i.e. bits 0 - 3) which makes up the full 8bits?
Thanks,
Mike