Detect if LCD connected

Vincent31
Benutzer
Avatar
Gender: n/a
Posts: 30
Registered: 07 / 2008
Subject:

Detect if LCD connected

 · 
Posted: 31.03.2021 - 17:01  ·  #1
Hello all,

I have a quick question...I am using a LCD display 2x16 on PortC, no problem, I import LCDport in program, but when LCD is not connected, my AVR has strange behaviour and becomes very slow...because I suppose all pins PortC for LCD are not connected...So is there a function to detect if LCD is connected or not, and if not disable LCD port and put it as simple output for example...like DDRC=$FF

Because my harware need to work with or without LCD....thanks for your help :-)

Vincent
pvs-deck
PowerUser
Avatar
Gender:
Age: 53
Homepage: pvs-deck.de
Posts: 1341
Registered: 02 / 2009
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 11:28  ·  #2
Hello Vincent31 ,

how is your LCD connected? 4bit, 8bit, SPI or I2c bus?

Which CPU ATMEGA or XMEGA?

E.g. with the I2c with an XMEGA you could use TWIstatE () to query whether the display is even available.

With the SPI, if the display has a read option, just read and switch off at TimeOut. You can e.g. write in a register and then just try to read from it, if it is there, you will get the written back, if not you run into the TimeOut and switch it off.

Hardware Option:
Many displays often have several GND pins, here you could simply query an input of the CPU with a pull-up.

If it is high, then it has positive power via the pull-up, if it is low, then it is pulled to low via a GND pin from the connector of the display and a display is available.

Thorsten
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 11:47  ·  #3
Hello Vincent,

I think you must not use the automatic initialisation of the display. First determine whether a display is connected, then initialise it manually. It doesn't matter which interface the display uses.

Harry
Vincent31
Benutzer
Avatar
Gender: n/a
Posts: 30
Registered: 07 / 2008
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 13:00  ·  #4
Hello Harry and Thorsten,

Thanks for reply. I am using Xmega64A4U, on PortC so not SPI or I2C, also, hardware is finished, cannot add pull up on LCD connector...

Harry, may be you are rigth, could add in program the compiler switch {nolcdinit) and test portC if LCD connected manually, and if connected launch function LCDinit of driver...

Now I have to see how testing if LCD connected, may be with a time out ?

Vincent
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 14:07  ·  #5
Hello Vincent,

you can only test one output of the LCD or input on the controller. Switch on the PullUp or PullDown (depending on the level) of the controller and see if the LCD works against it.

Harry
pvs-deck
PowerUser
Avatar
Gender:
Age: 53
Homepage: pvs-deck.de
Posts: 1341
Registered: 02 / 2009
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 15:27  ·  #6
Quote by Harry

Hello Vincent,

you can only test one output of the LCD or input on the controller. Switch on the PullUp or PullDown (depending on the level) of the controller and see if the LCD works against it.

Harry


Yes, I think Harry's solution here is the simplest, with no hardware changes.

Thorsten
Vincent31
Benutzer
Avatar
Gender: n/a
Posts: 30
Registered: 07 / 2008
Subject:

Re: Detect if LCD connected

 · 
Posted: 01.04.2021 - 16:04  ·  #7
Thanks, yes I think good solution, but AVRco should have a driver function to test if LCD connected....

Vincent
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   124   138 · Page-Gen-Time: 0.035115s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI