LCD and button interaction

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 and button interaction

Post by echase »

A typical hardware design has an LCD connected to PIC Port B. Also it has a few push buttons or a keypad that connects to this port. So it’s writing to LCD in output mode and reading from switches in input mode. Problem is that when a button is pressed it puts a logic high on the PIC pin which overrides the data being written to the LCD. Result is corrupt characters on LCD.

I have found that usually these corrupt characters get overwritten on next LCD update so not a huge problem. More worrying though is that often it completely freezes up the LCD with a corrupt display and even the next LCD Clear command does not clear it. Only way around it is a LCD Start command to reset it. Constant LCD restarts are not good idea though as prably wipes even a non corrupt display. So to eliminate or minimise corruption can I:-

1) In my Port B interrupt that reads the buttons could I immediately, upon detecting a button press, disable further data reads by the LCD (by outputting a 0 to LCD enable pin?), so PIC is still outputting new LCD data but LCD ignores it. After waiting a typical button press time (or somehow detecting the button being released) turn it back on again (with an LCD Start?) But would the LCD Start command also wipe/corrupt the LCD screen as I want it to keep the display showing the last screen before the button was pressed.

2) Or pause all LCD commands until the button is released? Don’t know how to do this unless I have IF loops that bypass all LCD commands every time a button is detected? Bit longwinded in my case as I have a huge number of LCD commands all over the code.

Do you know of a better way to do this?

I have a suspicion there would be less display corruption if the buttons were connected to earth instead so that they put a logic 0 on the PIC/LCD, but this is not the way Flowcode likes its buttons connected and you previously said you had no plans to change this default.

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

Re: LCD and button interaction

Post by Steve »

You could edit the C code for the LCD component (remember to keep a backup of the original though). In this edited version, you could check the state of the inputs before setting the lines to outputs and sending the chars to the LCD.

It should not be a problem for you to wire the switches differently. You will just need to remember to invert the logic in your own code.

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

Re: LCD and button interaction

Post by echase »

That may work thanks.

I guess the simplest way to do this is to connect the PIC straight to the LCD, not via resistors. Then use say a 1k resistor between the switch and PIC. That way if the switch is pressed when the port is writing to the LCD the data is not corrupted because the PIC transistors override the switch as the resistor stops the switch changing the port voltage. But once the port is set as an input the switches can be read.

Regrettably this circuit would not work in my case as I must have a resistor between PIC and LCD.

Post Reply