Detect if LCD connected

Vincent31
Benutzer
Avatar
Geschlecht: keine Angabe
Beiträge: 30
Dabei seit: 07 / 2008
Betreff:

Detect if LCD connected

 · 
Gepostet: 31.03.2021 - 17:01 Uhr  ·  #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
Geschlecht:
Alter: 54
Beiträge: 1343
Dabei seit: 02 / 2009
Betreff:

Re: Detect if LCD connected

 · 
Gepostet: 01.04.2021 - 11:28 Uhr  ·  #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
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Detect if LCD connected

 · 
Gepostet: 01.04.2021 - 11:47 Uhr  ·  #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
Geschlecht: keine Angabe
Beiträge: 30
Dabei seit: 07 / 2008
Betreff:

Re: Detect if LCD connected

 · 
Gepostet: 01.04.2021 - 13:00 Uhr  ·  #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
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Detect if LCD connected

 · 
Gepostet: 01.04.2021 - 14:07 Uhr  ·  #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
Geschlecht:
Alter: 54
Beiträge: 1343
Dabei seit: 02 / 2009
Betreff:

Re: Detect if LCD connected

 · 
Gepostet: 01.04.2021 - 15:27 Uhr  ·  #6
Zitat geschrieben von 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
Geschlecht: keine Angabe
Beiträge: 30
Dabei seit: 07 / 2008
Betreff:

Re: Detect if LCD connected

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

Vincent
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 14 · Cache Hits: 14   124   138 · Page-Gen-Time: 0.030338s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI