| 66 | Page 11 de la documentation : [[http://www.newhavendisplay.com/specs/NHD-0420DZ-FL-YBW.pdf | Datasheet du LCD de la plateforme]] |
| 67 | {{{#!c |
| 68 | 4-bit Initialization: |
| 69 | /**********************************************************/ |
| 70 | void command(char i) |
| 71 | { |
| 72 | P1 = i; //put data on output Port |
| 73 | D_I =0; //D/I=LOW : send instruction |
| 74 | R_W =0; //R/W=LOW : Write |
| 75 | Nybble(); //Send lower 4 bits |
| 76 | i = i<<4; //Shift over by 4 bits |
| 77 | P1 = i; //put data on output Port |
| 78 | Nybble(); //Send upper 4 bits |
| 79 | } |
| 80 | /**********************************************************/ |
| 81 | void write(char i) |
| 82 | { |
| 83 | P1 = i; //put data on output Port |
| 84 | D_I =1; //D/I=HIGH : send data |
| 85 | R_W =0; //R/W=LOW : Write |
| 86 | Nybble(); //Clock lower 4 bits |
| 87 | i = i<<4; //Shift over by 4 bits |
| 88 | P1 = i; //put data on output Port |
| 89 | Nybble(); //Clock upper 4 bits |
| 90 | } |
| 91 | /**********************************************************/ |
| 92 | void Nybble() |
| 93 | { |
| 94 | E = 1; |
| 95 | Delay(1); //enable pulse width >= 300ns |
| 96 | E = 0; //Clock enable: falling edge |
| 97 | } |
| 98 | /**********************************************************/ |
| 99 | void init() |
| 100 | { |
| 101 | P1 = 0; |
| 102 | P3 = 0; |
| 103 | Delay(100); //Wait >40 msec after power is applied |
| 104 | P1 = 0x30; //put 0x30 on the output port |
| 105 | Delay(30); //must wait 5ms, busy flag not available |
| 106 | Nybble(); //command 0x30 = Wake up |
| 107 | Delay(10); //must wait 160us, busy flag not available |
| 108 | Nybble(); //command 0x30 = Wake up #2 |
| 109 | Delay(10); //must wait 160us, busy flag not available |
| 110 | Nybble(); //command 0x30 = Wake up #3 |
| 111 | Delay(10); //can check busy flag now instead of delay |
| 112 | P1= 0x20; //put 0x20 on the output port |
| 113 | Nybble(); //Function set: 4-bit interface |
| 114 | command(0x28); //Function set: 4-bit/2-line |
| 115 | command(0x10); //Set cursor |
| 116 | command(0x0F); //Display ON; Blinking cursor |
| 117 | command(0x06); //Entry Mode set |
| 118 | } |
| 119 | /**********************************************************/ |
| 120 | }}} |