1) Ya que estoy usando todas las lineas del puerto D, tuve que estar conectando y desconectando las lineas PD0/PD1 las cuales son usadas para descargar el codigo, cada vez que le hacia modificaciones al codigo.
2) Use' PIND en lugar de PORTD para leer el bus de datos conectado al LCD.
3) https://askubuntu.com/questions/1056314/uploading-code-to-arduino-gives-me-the-error-avrdude-ser-open-cant-open-d
El siguiente codigo:
How to read from LCD DDRAM
https://www.avrfreaks.net/s/topic/a5C3l000000UDqBEAW/t067001
No funciona en el simulador de tinkercad.
Le tuve que hacer algunas adecuaciones para que funcionara en un circuito real:
//Los primeros 4 caracteres
//son copiados de la 1er linea a la segunda
//son copiados de la 1er linea a la segunda
//Usar PORTD o PIND para leer, muestra diferentes valores
//
#define LCD_RW_DELAY 10
int first_line = 0x80; // first line address
int second_line = 0xC0; // second line address
int ddram_info = 0x00;
void PortsSet()
{
PORTD = 0x00;
DDRD = 0xFF;
// PORTD pins are connected to D0....D7 LCD Data pins
PORTB = 0x00;
DDRB |= ( ( 1 << PB0 ) | ( 1 << PB1 ) | ( 1 << PB2 ));
// PB0 is connected to E pin , Enable
// PB1 is connected to R/W pin, Read/Write
// PB2 is connected to RS pin, Register Select
delay(10);
// enabling all the lines of the LCD
PORTB |= ( 1 << PB0 );
PORTD = 0x38;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
// Cursor ON, Blinking ON
PORTB = 0x01;
PORTD = 0x0F;
delay(10);
PORTB = 0x00;
delay(LCD_RW_DELAY);
// Cursor ON, Blinking ON
PORTB = 0x01;
PORTD = 0x01;
delay(10);
PORTB = 0x00;
delay(LCD_RW_DELAY);
}
void Write( char s[] )
{
short int i = 0;
for ( i = 0; i < strlen( s) ; i++ )
{
PORTB |= ( ( 1 << PB0 ) | ( 1 << PB2 ) );
delay(10);
PORTD = s[i];
PORTB &= ~( 1 << PB0 );
delay(10);
}
}
void GetChar()
{
PORTB = 0x00;//Write-Cmd
// setting the DDRAM adress at the
// beggining of the first LCD line, column 0
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = first_line;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
//==============================================
// I assumed that in order to receive information I
// have to set PORTD pins as input
//PORTD = 0xFF;//new
DDRD = 0x00;
delay(100);
//PORTD = 0xFF;//new
delay(LCD_RW_DELAY);
//reading the information from DDRAM
PORTB |= ( (1<<PB2)|(1<<PB1) );//Read-Data
delay(LCD_RW_DELAY);
PORTB |= ( 1 << PB0 );
delay(10); //wait for data setup
ddram_info = PIND; // read data
PORTB &= ~( 1 << PB0 );
//==============================================
// setting the portD as output in order to write the info into the second line
DDRD = 0xFF;
delay(LCD_RW_DELAY);
// writing the info readed from ddram
// writing into the second line
PORTB = 0x00;//Write-Cmd
//PORTD = 0x00;
delay(LCD_RW_DELAY);
// moving the cursor at the beginning of the
// second line, column 0
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = second_line++;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
//==============================================
// writing the info
//PORTB &= ~( 1 << PB1 );
delay(10);
PORTB |= ( 1 << PB2 );
delay(10);
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = ddram_info;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
}
void setup() {
PortsSet();
Write( "ABCDEFG ");
while( first_line <= 0x83 )
{
GetChar();
first_line++;
// next column of first line
}
}
void loop()
{
}
//
#define LCD_RW_DELAY 10
int first_line = 0x80; // first line address
int second_line = 0xC0; // second line address
int ddram_info = 0x00;
void PortsSet()
{
PORTD = 0x00;
DDRD = 0xFF;
// PORTD pins are connected to D0....D7 LCD Data pins
PORTB = 0x00;
DDRB |= ( ( 1 << PB0 ) | ( 1 << PB1 ) | ( 1 << PB2 ));
// PB0 is connected to E pin , Enable
// PB1 is connected to R/W pin, Read/Write
// PB2 is connected to RS pin, Register Select
delay(10);
// enabling all the lines of the LCD
PORTB |= ( 1 << PB0 );
PORTD = 0x38;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
// Cursor ON, Blinking ON
PORTB = 0x01;
PORTD = 0x0F;
delay(10);
PORTB = 0x00;
delay(LCD_RW_DELAY);
// Cursor ON, Blinking ON
PORTB = 0x01;
PORTD = 0x01;
delay(10);
PORTB = 0x00;
delay(LCD_RW_DELAY);
}
void Write( char s[] )
{
short int i = 0;
for ( i = 0; i < strlen( s) ; i++ )
{
PORTB |= ( ( 1 << PB0 ) | ( 1 << PB2 ) );
delay(10);
PORTD = s[i];
PORTB &= ~( 1 << PB0 );
delay(10);
}
}
void GetChar()
{
PORTB = 0x00;//Write-Cmd
// setting the DDRAM adress at the
// beggining of the first LCD line, column 0
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = first_line;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
//==============================================
// I assumed that in order to receive information I
// have to set PORTD pins as input
//PORTD = 0xFF;//new
DDRD = 0x00;
delay(100);
//PORTD = 0xFF;//new
delay(LCD_RW_DELAY);
//reading the information from DDRAM
PORTB |= ( (1<<PB2)|(1<<PB1) );//Read-Data
delay(LCD_RW_DELAY);
PORTB |= ( 1 << PB0 );
delay(10); //wait for data setup
ddram_info = PIND; // read data
PORTB &= ~( 1 << PB0 );
//==============================================
// setting the portD as output in order to write the info into the second line
DDRD = 0xFF;
delay(LCD_RW_DELAY);
// writing the info readed from ddram
// writing into the second line
PORTB = 0x00;//Write-Cmd
//PORTD = 0x00;
delay(LCD_RW_DELAY);
// moving the cursor at the beginning of the
// second line, column 0
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = second_line++;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
//==============================================
// writing the info
//PORTB &= ~( 1 << PB1 );
delay(10);
PORTB |= ( 1 << PB2 );
delay(10);
PORTB |= ( 1 << PB0 );
delay(10);
PORTD = ddram_info;
PORTB &= ~( 1 << PB0 );
delay(LCD_RW_DELAY);
}
void setup() {
PortsSet();
Write( "ABCDEFG ");
while( first_line <= 0x83 )
{
GetChar();
first_line++;
// next column of first line
}
}
void loop()
{
}
No comments:
Post a Comment