LCD component

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

LCD component

Post by echase »

Struggling with pin allocation as running out of pins in my design.

One way out would be to put the 4 data pins of the LCD on RB4-7 and the other 2 or 3 on the C port, as need pins RB1-3 for analogue inputs. Can that be done with Flowcode?

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

It is possible, but not easy. The latest release of Flowcode comes with externalised C code for a number of components, one being the LCD display. This means it is possible to modify the code that drives the LCD module.

Unfortunately, such mods will not be too "clean" because the component itself expects all pins to be on the same port. But it is possible.

The external code file is called "LCDDisplay_Code.c" and is in the "Components" subdirectory of Flowcode. If you do edit this file, make a backup of the original first. The following functions within the file will need to be edited:

Code: Select all

%i_RawSend
Start
For simplicity, I'll assume you want the RS and E lines onto C0 and C1. First, you will need to set the component connections within Flowcode for the 4 data lines of the LCD. You can totally ignore the E and RS pins, because we will be overriding these settings in the code.

The "Start" function is relatively easy to change:

Code: Select all

	clear_bit(%i_TRIS, %i_RS);
	clear_bit(%i_TRIS, %i_E);
needs to become:

Code: Select all

	clear_bit(trisc, 0);
	clear_bit(trisc, 1);
The "%i_RawSend" function is a bit more difficult to fix. Basically, each line that references "%i_RS" and "%i_E" needs to be changed to refer to the appropriate port and pin. Here is an updated version of this function with the required mods:

Code: Select all

void %i_RawSend(char nIn, char nMask)
{
	unsigned char pt;
	unsigned char outVal;
	outVal = %i_PORT;
	clear_bit(outVal, %i_BIT0);
	clear_bit(outVal, %i_BIT1);
	clear_bit(outVal, %i_BIT2);
	clear_bit(outVal, %i_BIT3);
	clear_bit(portc, 0);  //RS
	clear_bit(portc, 1);  //E
	pt = ((nIn >> 4) & 0x0f);
	if (pt & 0x01)
	    set_bit(outVal, %i_BIT0);
	if (pt & 0x02)
	    set_bit(outVal, %i_BIT1);
	if (pt & 0x04)
	    set_bit(outVal, %i_BIT2);
	if (pt & 0x08)
	    set_bit(outVal, %i_BIT3);
	if (nMask)
	    set_bit(portc, 0);  //RS
	%i_PORT = outVal;
	%i_DELAY;
	set_bit (portc, 1);  //E
	%i_DELAY;
	clear_bit (portc, 1);  //E
	pt = (nIn & 0x0f);
	%i_DELAY;
	outVal = %i_PORT;
	clear_bit(outVal, %i_BIT0);
	clear_bit(outVal, %i_BIT1);
	clear_bit(outVal, %i_BIT2);
	clear_bit(outVal, %i_BIT3);
	clear_bit(portc, 0);  //RS
	clear_bit(portc, 1);  //E
	if (pt & 0x01)
	    set_bit(outVal, %i_BIT0);
	if (pt & 0x02)
	    set_bit(outVal, %i_BIT1);
	if (pt & 0x04)
	    set_bit(outVal, %i_BIT2);
	if (pt & 0x08)
	    set_bit(outVal, %i_BIT3);
	if (nMask)
	    set_bit(portc, 0);  //RS
	%i_PORT = outVal;
	%i_DELAY;
	set_bit (portc, 1);  //E
	%i_DELAY;
	clear_bit (portc, 1);  //E
	%i_DELAY;
}
The lines I have changed have been suffixed with "//E" or "//RS".

I have not tested this code.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Post by echase »

Many thanks. I am actually going to put E and RS on C6 and C7. I assume that, wherever you have put 0 and 1 in your code agaist E and RS lines, it just becomes 6 and 7 in my case?

Problem is that on the 16F886 the lower bits on Ports B and C are used for interesting things like PWM and A/Ds so it’s hard to use 6 lines on either Port just for LCD. No doubt other users think the functions on the higher bits are useful or are cleverer than me at sharing lines.
Last edited by echase on Fri Aug 17, 2007 11:02 am, edited 1 time in total.

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

You are correct - 0 & 1 become 6 & 7.

I think we will eventually change the LCD component so that the pins do not need to be on the same port.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Post by echase »

Are there likely to be any timing issues with mismatches in timing between the 2 ports? In the extreme if data 1 and 2 were on port B and data 3 and 4 on Port C would the hardware notice any timing problem, as compared with it all being on port B say?

My code runs incredibly slowly for power saving reasons but I guess the timing of the pulses to the LCD are independent of clock speed.

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

The only change in the timing is that the RS line is altered 1 instruction before the data is written (the previous code wrote the data and RS lines at the same time). I don't think this will cause any problems because the E pin clocks the data and the timing for this remains the same.

Post Reply