Guest MirceaMurar Posted December 10, 2008 Share Posted December 10, 2008 Salut! Am intampinat o problema la citirea din memoria DDRAM a LCD-ului, va rog daca se poate sa ma ajutati Lucru la un proiect in care folosesc un LCD 4x20 si un Atmega16. In mare problema este urmatoarea: am un sir de caractere pe prima linie a LCD-ului, acest sir eu trebuie sa-l scriu si pe linia 2. Am pus si codul scris, in cazul in care nu intelegeti undeva ce am vrut sa fac, va rog sa ma intrebati #define F_CPU 1000000UL#include <avr/io.h>#include <util/delay.h>#include <string.h>void PortsSet();void Write( char s[] );void GetChar();int first_line = 0x80; // adress of the first line of LCDint second_line = 0xC0; // second line adresschar ddram_info = 0x00; int main(){ PortsSet(); Write("ABCDEFG"); // vreau sa citesc primele 4 caractere while( first_line <= 0x83 ) { GetChar(); first_line++; // next column of first line } return 0;}void PortsSet(){ PORTC = 0x00; DDRC = 0xFF; // PORTC pins are connected to D0....D7 LCD Data pins PORTD = 0x00; DDRD |= ( ( 1 << PD0 ) | ( 1 << PD1 ) | ( 1 << PD2 )); // PD0 is connected to E pin , Enable // PD1 is connected to R/W pin, Read/Write // PD2 is connected to RS pin, Register Select // second LCD line set PORTD |= ( 1 << PD0 ); PORTC = 0x38; PORTD &= ~( 1 << PD0 ); _delay_ms( 10 ); // Cursor ON, Blinling ON PORTD = 0x01; PORTC = 0x0F; PORTD = 0x00; _delay_ms( 10 );}void Write( char s[] ){ short int i = 0; for ( i = 0; i < strlen( s) ; i++ ) { PORTD |= ( ( 1 << PD0 ) | ( 1 << PD2 ) ); PORTC = s[i]; PORTD &= ~( 1 << PD0 ); _delay_ms( 5 ); }}void GetChar(){ PORTD = 0x00; // setting the DDRAM adress at the beggining of the first LCD line, column 0; PORTD |= ( 1 << PD0 ); PORTC = first_line; PORTD &= ~( 1 << PD0 ); _delay_ms( 10 ); // I assumed that in order to receive information I have to set PORTC pins as input DDRC = 0x00; _delay_ms( 100 ); //reading the information from DDRAM PORTD |= ((1<<PD2)|(1<<PD1)|(1<<PD0)); ddram_info = PINC; _delay_ms( 100 ); PORTD &= ~(1<<PD0); _delay_ms( 1000 ); // setting the portC as output DDRC = 0xFF; _delay_ms( 1000 ); PORTD &= ~(1<<PD1); //writing the info readed from ddram from the specified adress, //writing into the second line PORTD = 0x00; PORTC = 0x00; _delay_ms( 1000 ); //moving the cursor at the beggining of the second line, column 0 PORTD |= ( 1 << PD0 ); PORTC = second_line++; PORTD &= ~( 1 << PD0 ); _delay_ms( 100 ); // writing the info PORTD |= (( 1 << PD0 ) | ( 1 << PD2 ) ); PORTC = ddram_info; PORTD &= ~( 1 << PD0 ); _delay_ms( 1000 );} Link to comment Share on other sites More sharing options...
Laci Posted December 10, 2008 Share Posted December 10, 2008 Se pare ca ai probleme de timing:"//reading the information from DDRAM PORTD |= ((1< Link to comment Share on other sites More sharing options...
Guest MirceaMurar Posted December 11, 2008 Share Posted December 11, 2008 Mersi mult!Am inlocuit asa cum mi-ai spus si a functionat.Am fost incercat si eu ceva asemanator dar tot fara rezultat.Multumesc inca odata! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.