I'm using a PIC 16F877A for a LCD project and had a thought.
I was wondering when using #define LCD_DATA PORTB
Is it possible to only define the lower 4 bits.
If I use #define LCD_DATA PORTB, I'm using B0 - B3 for the LCD display
B6 and B7 for ICSP and B4 and B5 are going to waste.
No real big deal with the 40 pin chips but on a smaller pin count it means loosing 2 I/O pins.
As you know I need a minimum of 6 data lines to operate a LCD.
If I could define just the lower 4 bits, the other four bits could be utilized for other purposes.
Just Curious.
Thankyou
Bill
Adding the line
#define LCD_DATA PORTB doesn't waste anything, and truthfully, it doesn't really
do anything either!
The #define is a compiler directive, and it allows you to substitute text. So anywhere that you have typed "LCD_DATA", the compiler's pre-processor will replace that text with "PORTB"
before compiling. That line does absolutely nothing else. It doesn't reserve PORTB for any specific use, it doesn't configure anything, it literally does nothing other than accomplish a textual search and replace. It only makes your code more readable by allowing you to refer to PORTB with a more meaningful name.
You can still use other bits of PORTB for anything else. E.g. if you have a "busy" LED connected to Port B bit 7, you could also add:
#define BUSY_LED PORTBbits.RB7Then you can just do
BUSY_LED = 1; or
BUSY_LED = 0; to turn it on and off. This won't affect the bits you are using for the LCD.