{"id":927,"date":"2015-03-28T14:52:33","date_gmt":"2015-03-28T18:52:33","guid":{"rendered":"https:\/\/ve2cuy.wordpress.com\/?page_id=927"},"modified":"2015-03-28T14:52:33","modified_gmt":"2015-03-28T18:52:33","slug":"pic-18f-exemple-pour-afficher-sur-lcd-avec-plibxlcd-h","status":"publish","type":"page","link":"https:\/\/ve2cuy.com\/blog\/index.php\/pic-18f-exemple-pour-afficher-sur-lcd-avec-plibxlcd-h\/","title":{"rendered":"PIC 18F &#8211; Exemple pour afficher sur LCD avec plib\/xlcd.h"},"content":{"rendered":"<p>Sample code that displays on a LCD using the xlcd XC8\u00a0library<\/p>\n<p>Note: The internal clock is used with the default clock\u00a0rate of 1 MHz.<\/p>\n<p><a href=\"https:\/\/drive.google.com\/uc?export=download&amp;id=0BwVyrqVfxGkRcUtGclVtMUNIUXM\">Download<\/a>\u00a0proteus project using a PIC 18F85K22:<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>Voici un exemple de code qui permet d&rsquo;afficher sur un LCD en utilisant la librairie xlcd sous xc8<\/p>\n<p>Note: L&rsquo;horloge interne est utilis\u00e9e avec la cadence par d\u00e9faut (1 Mhz).<\/p>\n<h4>Directives de connexions<\/h4>\n<table>\n<tbody>\n<tr>\n<th>LCD<\/th>\n<th>PIN<\/th>\n<th>PIC<\/th>\n<th>PIN<\/th>\n<\/tr>\n<tr>\n<td>RW<\/td>\n<td>5<\/td>\n<td>RB6<\/td>\n<td>39<\/td>\n<\/tr>\n<tr>\n<td>RS<\/td>\n<td>4<\/td>\n<td>RB5<\/td>\n<td>38<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>6<\/td>\n<td>RB4<\/td>\n<td>37<\/td>\n<\/tr>\n<tr>\n<td>D4<\/td>\n<td>11<\/td>\n<td>RB0<\/td>\n<td>33<\/td>\n<\/tr>\n<tr>\n<td>D5<\/td>\n<td>12<\/td>\n<td>RB1<\/td>\n<td>34<\/td>\n<\/tr>\n<tr>\n<td>D6<\/td>\n<td>13<\/td>\n<td>RB2<\/td>\n<td>35<\/td>\n<\/tr>\n<tr>\n<td>D7<\/td>\n<td>14<\/td>\n<td>RB3<\/td>\n<td>36<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"http:\/\/ve2cuy.com\/blog\/wp-content\/uploads\/2014\/08\/montage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-878\" src=\"http:\/\/ve2cuy.com\/blog\/wp-content\/uploads\/2014\/08\/montage.png\" alt=\"montage\" width=\"630\" height=\"420\" srcset=\"https:\/\/ve2cuy.com\/blog\/wp-content\/uploads\/2014\/08\/montage.png 1024w, https:\/\/ve2cuy.com\/blog\/wp-content\/uploads\/2014\/08\/montage-300x200.png 300w, https:\/\/ve2cuy.com\/blog\/wp-content\/uploads\/2014\/08\/montage-768x513.png 768w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/a>R\u00e9f\u00e9rence <a href=\"http:\/\/www.studentcompanion.co.za\/post\/2013\/05\/21\/Interfacing-LCD-Display-With-PIC-Microcontroller-XC8\">LCD<\/a><!--more--><\/p>\n<p>[sourcecode language=\u00a0\u00bbcpp\u00a0\u00bb]<br \/>\n\/*<br \/>\n* Info sur le LCD: http:\/\/www.studentcompanion.co.za\/post\/2013\/05\/21\/Interfacing-LCD-Display-With-PIC-Microcontroller-XC8<br \/>\n* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n* Description: Afficher sur le LCD en utilisant plib\/xlcd.h<br \/>\n* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n* Directives de connexions du PIC avec le LCD:<br \/>\n*<br \/>\n* Ce projet utilise les valeurs par d\u00e9faut de plib\/xlcd.h sur BUS 4 bits<br \/>\n*<br \/>\n* LCD PIN PIC PIN<br \/>\n* RW  5   RB6 39<br \/>\n* RS  4   RB5 38<br \/>\n* E   6   RB4 37<br \/>\n*<br \/>\n* DATA sur 4 bits<br \/>\n* LCD PIN PIC PIN<br \/>\n* D4  11  RB0 33<br \/>\n* D5  12  RB1 34<br \/>\n* D6  13  RB2 35<br \/>\n* D7  14  RB3 36<br \/>\n*\/<\/p>\n<p>#include &lt;xc.h&gt;<br \/>\n#include &lt;plib\/xlcd.h&gt;<\/p>\n<p>#pragma config FOSC = INTOSC_EC  \/\/ Utilisation de l&rsquo;OSC interne avec vitesse par defaut (1Mhz)<br \/>\n#pragma config LVP = 0;          \/\/ LCD ne fonctionne pas avec ce bit \u00e0 ON! Quelqu&rsquo;un peut expliquer pourquoi?<br \/>\n#define _XTAL_FREQ 1000000       \/\/ Constante requise pour __delay_ms()<br \/>\n#define END_OF_TIME 1<br \/>\n#define LINE_2 0x40<\/p>\n<p>\/\/ ***************************************************<br \/>\n\/\/ Prototypes des fonctions locales au projet<br \/>\n\/\/ ***************************************************<br \/>\nvoid init_XLCD(void);<br \/>\nvoid cls(void);<br \/>\nvoid DelayFor18TCY(void);<br \/>\nvoid DelayPORXLCD(void);<br \/>\nvoid DelayXLCD(void);<br \/>\nvoid uneDemieSeconde(void);<br \/>\nvoid afficherMsgAvecDelai(char * msg[], int sec, int position);<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid main(void) {<br \/>\n\/\/ ***************************************************<br \/>\n TRISD = 0;<\/p>\n<p> init_XLCD();<\/p>\n<p> afficherMsgAvecDelai(&quot;Attention le&quot;, 1, 0);<br \/>\n afficherMsgAvecDelai(&quot;spectacle &quot;, 1, LINE_2);<br \/>\n afficherMsgAvecDelai(&quot;debute NOW! &quot;, 3, 0);<br \/>\n cls();<\/p>\n<p> while (END_OF_TIME) {<br \/>\n   PORTD = 0xFF;<br \/>\n   afficherMsgAvecDelai(&quot;Je suis le &quot;, 1, 0);<br \/>\n   afficherMsgAvecDelai(&quot;message du jour&quot;, 1, 0);<br \/>\n   afficherMsgAvecDelai(&quot;** Be happy! **&quot;, 2, LINE_2);<br \/>\n   PORTD = 0x00;<br \/>\n   uneDemieSeconde(); \/\/delay();<br \/>\n   cls();<br \/>\n } \/\/ while END_OF_TIME<br \/>\n} \/\/ main()<\/p>\n<p>\/\/ ***************************************************<br \/>\n\/\/ Fonctions locales au projet<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid init_XLCD(void)<br \/>\n\/\/ ***************************************************<br \/>\n{<br \/>\n OpenXLCD(FOUR_BIT&amp;LINES_5X7); \/\/ configure LCD: 4-bit, 5x7char, multi-lines<br \/>\n while(BusyXLCD());            \/\/ Wait until LCD !busy<br \/>\n WriteCmdXLCD(0x06);           \/\/ cursor right, don&rsquo;t shift display<br \/>\n WriteCmdXLCD(0x0C);           \/\/ display on without cursor<br \/>\n } \/\/ init_XLCD<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid cls(void){<br \/>\n\/\/ ***************************************************<br \/>\n while(BusyXLCD());  \/\/Check if the LCD controller is not busy<br \/>\n WriteCmdXLCD(0x01); \/\/ Clear LCD<br \/>\n} \/\/ cls<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid uneDemieSeconde(void){<br \/>\n\/\/ ***************************************************<br \/>\n for (int i=0;i&lt;10;i++)<br \/>\n   __delay_ms(50);<br \/>\n} \/\/ uneDemieSeconde<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid afficherMsgAvecDelai(char * msg[], int sec, int position) {<br \/>\n\/\/ ***************************************************<br \/>\n while(BusyXLCD());<br \/>\n SetDDRamAddr(position);<br \/>\n while(BusyXLCD());<br \/>\n putrsXLCD( msg );<br \/>\n while(BusyXLCD());<br \/>\n for (int i = 0 ; i&lt;sec; i++) {<br \/>\n   uneDemieSeconde();<br \/>\n }<br \/>\n} \/\/ afficherMsgAvecDelai<\/p>\n<p>\/\/ ***************************************************<br \/>\n\/\/ Impl\u00e9mentation des routines de d\u00e9lais pour plib\/xlcd.h<br \/>\n\/\/ Note: Il faut d\u00e9finir la constante suivante:<br \/>\n\/\/ #define _XTAL_FREQ 8000000 \/\/ Note: 8MHz est un exemple<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid DelayFor18TCY(void)<br \/>\n{ __delay_us(36); \/\/ Value of &rsquo;18&rsquo; did not work for me!<br \/>\n}<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid DelayPORXLCD(void)<br \/>\n{ __delay_ms(15); }<\/p>\n<p>\/\/ ***************************************************<br \/>\nvoid DelayXLCD(void)<br \/>\n{ __delay_ms(5); }<\/p>\n<p>[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sample code that displays on a LCD using the xlcd XC8\u00a0library Note: The internal clock is used with the default clock\u00a0rate of 1 MHz. Download\u00a0proteus project using a PIC 18F85K22: &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Voici un exemple de code qui permet d&rsquo;afficher sur un LCD en utilisant la librairie xlcd sous xc8 Note: L&rsquo;horloge interne est utilis\u00e9e avec [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-927","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/pages\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":0,"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/pages\/927\/revisions"}],"wp:attachment":[{"href":"https:\/\/ve2cuy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}