215
Junior Member level 1
- Joined
- Mar 22, 2014
- Messages
- 17
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 264
I have this microcontroler with this LCD(DEM16216) mounted on it which i cannot initialize.
Only 4 of the pins are connected which thereby means it runs in a 4 bit mode.
I've looked the datasheet for it (DEM16216) , which gives an step by step guide on how to do it, but for reason it does not work for me...
Could someone tell me why this isn't working for me..
This is the datasheet for my LCD http://www.gaw.ru/pdf/lcd/lcm/Display/char/DEM16216SYH-LY.PDF
The one my teacher recomended to me was this one
**broken link removed**
init is performed outside of a superloop, command is performed inside a superloop.
Could explain why this isn't working??
Only 4 of the pins are connected which thereby means it runs in a 4 bit mode.
I've looked the datasheet for it (DEM16216) , which gives an step by step guide on how to do it, but for reason it does not work for me...
Could someone tell me why this isn't working for me..
This is the datasheet for my LCD http://www.gaw.ru/pdf/lcd/lcm/Display/char/DEM16216SYH-LY.PDF
The one my teacher recomended to me was this one
**broken link removed**
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 #include"screen.h" void nibble_value(INT8U binary_value) { if((binary_value << 3) == 1) //DB7 GPIO_PORTB_DATA_R &= ~(0b00000001 << 3); else GPIO_PORTB_DATA_R |= (0b00000001 << 3); if((binary_value << 2) == 1) //DB6 GPIO_PORTB_DATA_R &= ~(0b00000001 << 2); else GPIO_PORTB_DATA_R |= (0b00000001 << 2); if((binary_value << 1) == 1) //DB5 GPIO_PORTB_DATA_R &= ~(0b00000001 << 1); else GPIO_PORTB_DATA_R |= (0b00000001 << 1); if((binary_value << 0) == 1) // DB4 GPIO_PORTB_DATA_R &= ~(0b00000001 << 0); else GPIO_PORTB_DATA_R |= (0b00000001 << 0); } void insert_value (INT8U binary_value) { if((binary_value << 7) == 1) // RS GPIO_PORTA_DATA_R &= ~(0b00000001 << 7); else GPIO_PORTA_DATA_R |= (0b00000001 << 7); if((binary_value << 6) == 1) //RW GPIO_PORTA_DATA_R &= ~(0b00000001 << 6); else GPIO_PORTA_DATA_R |= (0b00000001 << 6); if((binary_value << 5) == 1) //DB7 GPIO_PORTB_DATA_R &= ~(0b00000001 << 5); else GPIO_PORTB_DATA_R |= (0b00000001 << 5); if((binary_value << 4) == 1) //DB6 GPIO_PORTB_DATA_R &= ~(0b00000001 << 4); else GPIO_PORTB_DATA_R |= (0b00000001 << 4); if((binary_value << 3) == 1) //DB5 GPIO_PORTB_DATA_R &= ~(0b00000001 << 3); else GPIO_PORTB_DATA_R |= (0b00000001 << 3); if((binary_value << 2) == 1) // DB4 GPIO_PORTB_DATA_R &= ~(0b00000001 << 2); else GPIO_PORTB_DATA_R |= (0b00000001 << 2); if((binary_value << 1) == 1) // debug; GPIO_PORTB_DATA_R &= ~(0b00000001 << 1); else GPIO_PORTB_DATA_R |= (0b00000001 << 1); if((binary_value << 0) == 1) // debug redLed(ON); else redLed(OFF); } void enable_pin (int a) { if (a) { GPIO_PORTB_DATA_R |= 0x40; // Enables "enable" pin redLed(ON); //Debug } else{ GPIO_PORTB_DATA_R &= 0xBF; //Disables "enable "pin redLed(OFF); //debug } } void screen_init( void ) { //POwer on MILLISEC(100); // Special case Function set //----------------------------------------------------------------// enable_pin(ON); // enable pin on MILLISEC(1); //1 ms delay nibble_value(0x03); // DB5 = 1, DB4 = 1 enable_pin(OFF); // enable pin off MILLISEC(15); // 5 ms delaay enable_pin(ON); //enable pin on MILLISEC(1); // 1 ms delay nibble_value(0x03); // DB5 = 1, DB4 = 1 enable_pin(OFF); // Enable pin off MILLISEC(15); // 5 ms delay enable_pin(ON); //enable pin on MILLISEC(1); //1 ms delay nibble_value(0x03); // DB5 = 1, DB4 = 1 enable_pin(OFF); // enable pin off MILLISEC(5); // 5 ms delay //-----------------------------------------------------------------// //initial Function set //-----------------------------------------------------------------// //enable_pin(ON); // enable pin on MILLISEC(1); // 1 ms delay nibble_value(0x02); // 0x02 = 0b00000010 => DB5 = 1 enable_pin(OFF); // enable pin = off MILLISEC(5); // 5 ms delay //----------------------------------------------------------------// //Function set //----------------------------------------------------------------// enable_pin(ON); // enable pin = on MILLISEC(1); // 1 ms delay nibble_value(0x02); // 0x02 = 0b00000010 => DB5 = 1 enable_pin(OFF); // enable pin = off MILLISEC(5); // 5 ms delay enable_pin(ON); // enable pin on MILLISEC(1); // 1 ms delay nibble_value(0x08); // 0x08 = 0b1000 n = 1 and f = 0 => DB7 = 1 enable_pin(OFF); // enable pin = off MILLISEC(5); // 5 ms delay //----------------------------------------------------------------// //Display On/Off //----------------------------------------------------------------// enable_pin(ON); //enable pin = on MILLISEC(1); // delay = 1 ms nibble_value(0x00); // ZERO enable_pin(OFF); //enable pin = off MILLISEC(5); // delay 5 ms enable_pin(ON); // enable pin = on MILLISEC(1); // delay = 1 ms nibble_value(0x08); // DB7 = 1 => display off enable_pin(OFF); // enable pin = off MILLISEC(5); // delay = 5 ms //---------------------------------------------------------------// //Clear Display //---------------------------------------------------------------// enable_pin(ON); // enable pin = on MILLISEC(1); // delay = 1 ms nibble_value(0b00000000); // Zero enable_pin(OFF); // Enable pin = off MILLISEC(5); // Delay = 5 ms enable_pin(ON); // enable = on MILLISEC(1); // delay = 1 ms nibble_value(0b00000001); // No configurable bits, CLEAR Display enable_pin(OFF); // enable = off MILLISEC(5); // delay = 5 ms //---------------------------------------------------------------// //Entry Mode set //---------------------------------------------------------------// enable_pin(ON); // enable pin = on MILLISEC(1); // delay = 1 ms nibble_value(0b00000000); // Zero enable_pin(OFF); // Enable pin = off MILLISEC(5); // Delay = 5 ms enable_pin(ON); // enable = on MILLISEC(1); // delay = 1 ms nibble_value(0b00000110); // DB6 = 1, DB5 = 1 (increment by 1) , DB4 = 0 (No shift) enable_pin(OFF); // enable = off MILLISEC(5); // delay = 5 ms //---------------------------------------------------------------// } void command (void) { //Command //---------------------------------------------------------------// enable_pin(ON); //enable pin on MILLISEC(1); //delay 1 ms nibble_value(0b00000000); // Zero MILLISEC(1); //delay 1 ms enable_pin(OFF); //Enable pin off MILLISEC(3); //delay 3 ms //--------------------------------------------------------------// //Command //---------------------------------------------------------------// enable_pin(ON); //enable pin on MILLISEC(1); //delay 1 ms nibble_value(0b00001111); // D = 1, C = 1 , B = 1 => display on, cursor on and blinking on.. MILLISEC(1); //delay 1 ms enable_pin(OFF); //Enable pin off MILLISEC(3); //delay 3 ms //--------------------------------------------------------------// }
init is performed outside of a superloop, command is performed inside a superloop.
Could explain why this isn't working??
Last edited: