{"id":811,"date":"2024-06-22T17:54:12","date_gmt":"2024-06-22T17:54:12","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=811"},"modified":"2024-08-11T14:48:03","modified_gmt":"2024-08-11T14:48:03","slug":"lcd-interfacing","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=811","title":{"rendered":"LCD Interfacing"},"content":{"rendered":"<p>A LCD display is nothing but a set of pixels. If any character sends to display it only glow the dot pixels that required. Standard alphanumeric LCD display can accept 8bit data bytes or 4bit nibble. In 8bit configuration all the bits of corresponding port is used and in 4bit configuration only four bits are used that are connected to D4-D7 at the LCD display. We only learn about 4bit operating mode. Both data &amp; command can be send to LCD pin D4-D7 through only 3 controlling pin E, RS &amp; <img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/rw.jpg\" alt=\"\" width=\"36\" height=\"19\" \/> . Pin <img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/rw.jpg\" alt=\"\" width=\"36\" height=\"19\" \/> is used for LCD read or write operation. Since we only write character to the LCD so <img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/rw.jpg\" alt=\"\" width=\"36\" height=\"19\" \/> in is ground all time.\u00a0<\/p>\n<style>\/*! elementor - v3.22.0 - 17-06-2024 *\/<br \/>\n.elementor-widget-image{text-align:center}.elementor-widget-image a{display:inline-block}.elementor-widget-image a img[src$=\".svg\"]{width:48px}.elementor-widget-image img{vertical-align:middle;display:inline-block}<\/style>\n<p>\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"590\" height=\"238\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/lcdmain.png\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/lcdmain.png 590w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/lcdmain-300x121.png 300w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t<\/p>\n<p>The pin RS(Register Select) is used for data &amp; command mode operation.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/RS.jpg\" alt=\"\" width=\"642\" height=\"75\" \/><\/p>\n<p>For both data mode and control mode the pin EN must go from 1 to 0. LCD has some command set to control the display.<\/p>\n<p>\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1175\" height=\"674\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/LCD-Code.jpg\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/LCD-Code.jpg 1175w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/LCD-Code-300x172.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/LCD-Code-1024x587.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/LCD-Code-768x441.jpg 768w\" sizes=\"(max-width: 1175px) 100vw, 1175px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t<\/p>\n<p>The dots are configured as follow-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/DOT-pixel.jpg\" alt=\"\" width=\"1454\" height=\"454\" \/><\/p>\n<p>Connect any GPIO to LCD D7, D6, D5, D4, E and RS.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/D4-D7.jpg\" alt=\"\" width=\"1348\" height=\"77\" \/><\/p>\n<p>From the table we see that only upper half of 4 bit of the LCD need to set or according to logic. So for 4bits data-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/4bit-send-mode.jpg\" alt=\"\" width=\"1284\" height=\"459\" \/><\/p>\n<p>Now next step is to send command or data<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/data-command.jpg\" alt=\"\" width=\"1272\" height=\"152\" \/><\/p>\n<p>All we are done with modes it\u2019s time to initialize the LCD and send data to display. Let\u2019s initialize the LCD first. To initialize the LCD it needs some steps-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/initilize.jpg\" alt=\"\" width=\"996\" height=\"265\" \/><\/p>\n<p>To send command\/data we need to set the upper 4bits in proper way. Since command\/data is send in 1byte\/8bits mode let\u2019s look at the function below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/4-bit-datacmd.jpg\" alt=\"\" width=\"1389\" height=\"237\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/c-structure-1.jpg\" alt=\"\" width=\"200\" height=\"37\" \/><\/p>\n<\/p>\n<h5><strong>String and its uses<\/strong><\/h5>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 A string is a sequence of characters that is treated as a single data item. The general form of declaration of a string variable \u2013<\/p>\n<h6>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>char string_name[size]=&#8221;your string<\/strong> <strong>&#8220;;<\/strong><\/h6>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 i.e. char name[20]= &#8221; EEE RUET 09 &#8220;<\/p>\n<p>Here,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string.jpg\" alt=\"\" width=\"1167\" height=\"92\" \/><\/p>\n<p>Therefore there are 11 single characters. The character string must not exact the size limit, otherwise an error occur.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i.e. char name[10]= &#8220;EEE RUET 09&#8221;\u00a0 \/\/Error<\/p>\n<h6><strong>Backslash character constants<\/strong><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/backslash.jpg\" alt=\"\" width=\"1154\" height=\"348\" \/><\/p>\n<p><strong>scanf function<\/strong><\/p>\n<h6>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Header file\u00a0 <strong>#include&lt;stdio.h&gt;<\/strong><\/h6>\n<p>here stdio.h represents standard i\/o function.<\/p>\n<p>Format<\/p>\n<h6>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>sprinf(*char, &#8220;<\/strong> <strong>character<\/strong> <strong>_declaration &#8220;);<\/strong><\/h6>\n<p>Here * denotes for pointer that will be discuss in the memory section. But string pointer is same as sting so no burry about the pointer. The commonly used sprint format code as follow-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/variable-declearation.jpg\" alt=\"\" width=\"1166\" height=\"446\" \/><\/p>\n<p>Now it is time to write some characters to the LCD display. For writing characters we need some steps-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-code.jpg\" alt=\"\" width=\"1349\" height=\"387\" \/><\/p>\n<h6><strong>After connect LCD with AVR sometime the LCD display shown no contents, in this case vary the variable resistance slowly until the display show characters. The contract adjust is very essential in LCD display so care should be taken.<\/strong><\/h6>\n<p>The lcd.c and lcd.h has been ready you can download the file from link. Your program is to show the ANSI C character code to the LCD display-<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;avr\/io.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&lt;stdio.h&gt;\n#include&quot;lcd.h&quot;        \/\/ PORTD as LCD port\nchar name&#x5B;20];\nint main(void)\n{\nLCD_INIT();\nLCD_Clear();\nwhile(1)\n\t{\n\t\tfor(int i=0;i&lt;=127;i++)\n\t\t\t{\n\t\t\t\tLCD_write_string(1,1,&quot;***ANSI C code**&quot;);\n\t\t\t\tsprintf(name,&quot;%i No. char %c  &quot;,i,i);\n\t\t\t\tLCD_write_string(1,2,name);\n\t\t\t\t_delay_ms(1000);\n\t\t\t}\n\t}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/LCD-Interfacing.rar\" style=\"border-radius:16px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/LCD-Interfacing.rar\">Download the full program with proteus simulation<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A LCD display is nothing but a set of pixels. If any character sends to display it only glow the dot pixels that required. Standard alphanumeric LCD display can accept 8bit data bytes or 4bit nibble. In 8bit configuration all the bits of corresponding port is used and in 4bit configuration only four bits are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-811","post","type-post","status-publish","format-standard","hentry","category-i-o-port-operations"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=811"}],"version-history":[{"count":88,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions"}],"predecessor-version":[{"id":2541,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions\/2541"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}