I have a weird problem with LCD

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

Post Reply
hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

I have a weird problem with LCD

Post by hazic »

I use the LCD component and I have a weird bug in my program, it all works fine but once in a while when the LCD is changing the display I get a scrambled screen with random characters on random places of the LCD. Do you have an idea of what can cause such a thing?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I have a weird problem with LCD

Post by Benj »

Hello,

If you have interrupts that have functions that control the LCD as well as LCD functions in your main program then you can be halfway through a LCD write in your main when an interrupt occurs. If the interrupt also talks to the LCD then it will start a new write to the LCD and cause some corruption. If you regularily update the entire screen then using the LCD start instead of a clear will remove any corruption from the screen as it allwos the communications with the display to be restarted.

hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

Re: I have a weird problem with LCD

Post by hazic »

Hi,

Yes I have interrupt and both interupt and the main have LCD functions.
How can I prevent the interrupt from running in the middle of LCD function from the main? (the interrupt is occuring every 1 second)

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I have a weird problem with LCD

Post by Benj »

Hello,

You could either move all of your LCD functions to the main and pass a value back from the interrupt to send to the LCD.

Or you can add a LCD_Enable variable to your program. Set the variable to 0 at the start of your program and then set the variable to 1 just before any of the main calls to the LCD. Restore it back to 0 after your calls to the LCD. Then in your interrupt service routine you can check the variable and output to the LCD only if the variable is equal to 0.

Either way should eliminate your corruption problems.

hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

Re: I have a weird problem with LCD

Post by hazic »

the LCD_ENABLE method seems easier to apply but once in a while I will loose some output to the LCD from the interrupt routine, is that right?

hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

Re: I have a weird problem with LCD

Post by hazic »

and what about the LCD_CLEAR ? should I hange it to LCD_START?

hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

Re: I have a weird problem with LCD

Post by hazic »

Thank you for your great advice!
If I think now of what I did I see its really not smart to make such a big interrupt routine.
As you said I moved all functions out of the interrupt and now the interrupt only change a flag which I check in the main.

now just one more thing I'm not sure about, every one second I change the time displayed on the LCD without clearing the LCD (I only print the time on the same location) and when the is a button pressed I clear the LCD and refresh the display with new text, should I use start instead of clear?

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I have a weird problem with LCD

Post by Benj »

Hello,

Glad your up and running now. Your right the flag to control the interrupt would mean you would miss data every so often The way you have done it with things in the main is a much better approach.

The Start and the clear functions do pretty much the same thing in that they both result in a cleared display.

Using the start will guarentee that if corruption occurs then it will be cleared up on the next cycle.

However if you are not getting corruption anymore then using the clear command is more efficient as it takes less time to execute.

hazic
Posts: 24
Joined: Tue Jan 05, 2010 8:59 am
Been thanked: 1 time
Contact:

Re: I have a weird problem with LCD

Post by hazic »

Ok. I'll watch it if I will get more corruption I'll use the start command once in a while...
Thank you it helped me a lot!

Post Reply