Thursday, December 19, 2024

Mostrar en LCD lo que se envia por el puerto serie desde la PC

Se modifico' la siguiente parte resaltada con amarillo:
de modo que el display muestre, uno a uno, el caracter que sea enviado por el puerto serie desde la PC.
(En lugar de la cadena "ABCDEF")
 

// 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;
char in;
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++) {
    Serial.println("Input?");
    while(!Serial.available()) {}
    in = Serial.read();
    Serial.println(in);
    //send(string1[i],'d');
    send(in,'d');//send the entered char instead  
 
  }

//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()
{
}

No comments: