// C++ code
// integrate 4 functions into 1
// No funciona en el simulador
// pero si funciona en un display real
//
unsigned int send(unsigned char byte,char type) {
unsigned char valor;
unsigned char LSN = (byte & 0x0f);
unsigned char MSN = (byte & 0xf0);
//int ascii;
char msg[30];
//ascii = byte;
Serial.print("=");
Serial.println(type);
switch(type) {
case '4': PORTD = (LSN << 4);
PORTB = 0x04;
delay(5);
PORTD = (LSN << 4);
PORTB = 0x00;
break;
case 'c': PORTD = MSN;
PORTB = 0x04;
delay(5);
PORTD = MSN;
PORTB = 0x00;
PORTD = (LSN << 4);
PORTB = 0x04;
delay(5);
PORTD = (LSN << 4);
PORTB = 0x00;
break;
case 'd': sprintf(msg,"mensaje %d = %c",byte,byte);
Serial.println(msg);
PORTD = MSN;
PORTB = 0x05;
delay(5);
PORTD = MSN;
PORTB = 0x01;
PORTD = (LSN << 4);
PORTB = 0x05;
delay(5);
PORTD = (LSN << 4);
PORTB = 0x01;
break;
case 'r': DDRD = 0B00001111;
delay(10);
PORTB = 0x07;
delay(10);
PORTB = 0x04;
MSN = PIND & 0xf0;
delay(10);
PORTB = 0xfb;
Serial.println("READ:");
Serial.println(MSN,HEX);
delay(50);
PORTB = 0x07;
delay(10);
PORTB = 0x04;
LSN = PIND & 0xf0;
delay(10);
PORTB = 0xfb;
Serial.println("READ:");
Serial.println(MSN,HEX);
valor = MSN + (LSN >> 4);
delay(10);
DDRD = 0xFF;
delay(50);
break;
}
Serial.print(byte,HEX);
Serial.print("=");
Serial.println(byte,DEC);
return valor;
}
void setup() {
unsigned char value;
Serial.begin(9600);
//Serial.println("Yes");
DDRB = 0xFF;//Todo Salidas
DDRD = 0xFF;//Todo Salidas
delay(150);//Retardo mayor de 15ms
send(0x3,'4');
delay(50);//Retardo mayor de 4.1ms
send(0x3,'4');
delay(10);//Retardo mayor de 100us
send(0x3,'4');
send(0x2,'4');
send(0x2,'4');
//C for LCD 2 lineas y caracter 5x10 puntos
send(0xc,'4');
//send cmd 01
send(0x01,'c');
//send cmd 0c
send(0x0c,'c');
//send cmd 06
send(0x06,'c');
//send cmd 0f
send(0x0f,'c');
//send cmd 01
send(0x01,'c');
//send data
send(0x30,'d');
int i;
for(i = 0; i<9 ; i++){
send(0x31 + i,'d');
}
char string1[] = "ABCDEF";
for(i = 0; i < strlen(string1); i++) {
send(string1[i],'d');
}
//set cursor to line #2
send(0xc0,'c');
char string2[] = "Jorge";
for(i = 0; i < strlen(string2); i++) {
send(string2[i],'d');
}
//set cursor to line #2
send(0xc0,'c');
delay(500);
value = send(0x0,'r');
delay(500);
//set cursor to line #1
send(0x80,'c');
//poner ahi lo que se copio' de la linea 1
send(value,'d');
}
void loop()
{
}
Wednesday, December 18, 2024
Arduino - Liberar las lineas TX/RX para poder usar el puerto serie
Mover las lineas de control:
De: Puerto D
A: Puerto B
De modo que podamos usar el puerto serie para debug de futuras pruebas.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment