apuntes_Arduino/lcd/LCD-8-bits-metodo/LCD-8-bits-metodo.ino
jp.av.dev 85bf8bb429 proyectos renombrados, reestructuracion
pendientes crear, indexar y linkear readmes
2022-04-04 01:11:04 -04:00

163 lines
4.2 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

int DI = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};// use array to select pin for bus
int Enable = 2;
void LcdCommandWrite(int value) {
// define all pins
int i = 0;
for (i=DB[0]; i <= DI; i++) // assign value for bus
{
digitalWrite(i,value & 01);// for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification; here, its used for signal inversion.
value >>= 1;
}
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1); // wait for 1ms
digitalWrite(Enable,LOW);
delayMicroseconds(1); // wait for 1ms
}
void LcdDataWrite(int value) {
// initialize all pins
int i = 0;
digitalWrite(DI, HIGH);
digitalWrite(RW, LOW);
for (i=DB[0]; i <= DB[7]; i++) {
digitalWrite(i,value & 01);
value >>= 1;
}
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1);
digitalWrite(Enable,LOW);
delayMicroseconds(1); // wait for 1ms
}
void setup (void) {
int i = 0;
for (i=Enable; i <= DI; i++) {
pinMode(i,OUTPUT);
}
delay(100);
// initialize LCD after a brief pause
// for LCD control
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(64);
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(50);
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(20);
LcdCommandWrite(0x06); // set input mode
// auto-increment, no display of shifting
delay(20);
LcdCommandWrite(0x0E); // display setup
// turn on the monitor, cursor on, no flickering
delay(20);
LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0
delay(100);
LcdCommandWrite(0x80); // display setup
// turn on the monitor, cursor on, no flickering
delay(20);
}
void loop (void) {
LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0
delay(10);
LcdCommandWrite(0x80+3);
delay(10);
// write in welcome message
LcdDataWrite('F');
delay(50);
LcdDataWrite('u');
delay(50);
LcdDataWrite('z');
delay(50);
LcdDataWrite('a');
delay(50);
LcdDataWrite('n');
delay(50);
LcdDataWrite(' ');
delay(50);
LcdDataWrite('T');
delay(50);
LcdDataWrite('o');
delay(50);
LcdDataWrite('k');
delay(50);
LcdDataWrite('o');
delay(50);
LcdCommandWrite(0xc0+0); // set cursor position at second line, second position
delay(10);
LcdDataWrite('*');
LcdDataWrite('*');delay(70);
LcdDataWrite('T');delay(90);
LcdDataWrite('U');delay(110);
LcdDataWrite('R');delay(130);
LcdDataWrite('B');delay(150);
LcdDataWrite('O');delay(170);
LcdDataWrite('-');delay(200);
LcdDataWrite('M');delay(170);
LcdDataWrite('A');delay(150);
LcdDataWrite('S');delay(130);
LcdDataWrite('T');delay(110);
LcdDataWrite('E');delay(90);
LcdDataWrite('R');delay(70);
LcdDataWrite('*');
LcdDataWrite('*');
delay(3000);
LcdCommandWrite(0x01); // clear the screen, cursor returns to 0
delay(10);
LcdDataWrite('A');
LcdDataWrite('p');
LcdDataWrite('r');
LcdDataWrite('e');
LcdDataWrite('n');
LcdDataWrite('d');
LcdDataWrite('e');
LcdDataWrite(' ');
LcdDataWrite('a');
LcdDataWrite(' ');
LcdDataWrite('u');
LcdDataWrite('s');
LcdDataWrite('a');
LcdDataWrite('r');
LcdDataWrite(' ');
LcdDataWrite(' ');
LcdCommandWrite(0xc0);
LcdDataWrite(' ');
LcdDataWrite('T');
LcdDataWrite('E');
LcdDataWrite('R');
LcdDataWrite('M');
LcdDataWrite('U');
LcdDataWrite('X');
LcdDataWrite(',');
LcdDataWrite(' ');
LcdDataWrite('d');
LcdDataWrite('e');
LcdDataWrite('s');
LcdDataWrite('p');
LcdDataWrite('u');
LcdDataWrite('e');
LcdDataWrite('s');
delay(2000);
LcdCommandWrite(0xc02); // set mode as new characters replay old ones, where there is no new ones remain the same
delay(10);
LcdCommandWrite(0xc80+6); // set cursor position at first line, sixth position
delay(10);
LcdDataWrite('S');
LcdDataWrite('s');
LcdDataWrite('h');
LcdDataWrite(' ');
LcdDataWrite(' ');
LcdDataWrite(' ');
delay(3000);
}