Jump to content
Arduino

Ecran LCD alfanumeric cu conectare seriala

Recommended Posts

lcd-300x158.png

Ecranul LCD cu conectare seriala este capabil sa afiseze 32 de caractere alfanumerice, aranjate pe doua randuri.

Avantajul conectarii pe portul serial consta in eliberarea porturilor digitale Arduino (un LCD clasic necesita cel putin 4 porturi digitale).

Ecranul necesita un cablu pentru conectare tip brick pe 4 fire si un modul de tip senzor shield. Conectarea se face cat se poate de simplu, un cablu cu 4 fire se conecteaza in ecranul LCD si in portul serial al senzor shield-ului.

lcdconectat-300x221.png

Este important ca sa fie conectat cablul in acelasi mod si in senzor shield si in LCD (in sensul ca daca in LCD avem conectat cablul cu partea unde se vad cele 2 mufe de metal, atunci si in senzor shield trebuie introdus cu aceeasi parte in sus). Imediat dupa conectare, indiferent de programul care ruleaza pe Arduino, LCD-ul trebuie sa se aprinda. In caz contrar, incearca sa intorci unul dintre conectorii cablului invers. Daca tot nu functioneaza, inseamna ca este necesar sa ii setezi contrastrul si luminozitatea (cele doua potentiometre incadrate cu verde in imaginea de mai jos).

ecranLCDspate-300x143.png

Important : dat fiind ca ecranul LCD functioneaza pe portul serial, cablul va trebui scos din ecran atunci cand urci un program pe Arduino. Daca nu il scoti, nu se intampla nimic, doar ca vei primi o eroare care te va informa ca instalarea programului a esuat.

Exemplu de cod


view sourceprint?
void setup() {
Serial.begin(9600);
}

void loop(){
Serial.print("$CLEAR\n\r");
Serial.print("$GO 1 1\n\r");
Serial.print("$PRINT http://www.tehnorama.ro\n\r");
delay(10000);
}

Este de remarcat combinatia “\n\r” de la finalul fiecarei linii. Este foarte important sa nu o omiti, pentru ca ea semnalizeaza ecranului ca s-a incheiat comanda curenta.

Modulul este disponibil pe RoboFun.ro

Sursa: Tehnorama

Link to comment
Share on other sites

Pentru celelalte LCD_uri codul pentru afisare :) :

unsigned char x[24]={0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,

0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,

0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};

unsigned char y[24]={0x1C,0x18,0x14,0x10,0x0C,0x08,0x04,0x00, //PORTA=0x40

0x1C,0x18,0x14,0x10,0x0C,0x08,0x04,0x00, //PORTA=0x80

0x1E,0x1A,0x16,0x12,0x0E,0x0A,0x06,0x02 //PORTA=0x00

};

void afisx(unsigned char ix){

unsigned int i;

if (zoom_crt<ZOOM1){

PORTA=x[ix];

delay_for(LATENTA1);

}

else if (zoom_crt<ZOOM2) {

PORTA=x[ix];

delay_for(LATENTA2);

if (ix+1<24){

PORTA=x[ix+1];

delay_for(LATENTA2);

}

}else{

if (zoom_crt<ZOOM3){

PORTA=x[ix];

delay_for(LATENTA3);

if (ix-1>=0){

PORTA=x[ix-1];

delay_for(LATENTA3);

}

if (ix+1<24){

PORTA=x[ix+1];

delay_for(LATENTA3);

}

}else{

PORTA=x[ix];

delay_for(LATENTA4);

if (ix-1>=0){

PORTA=x[ix-1];

delay_for(LATENTA4);

}

if (ix+1<24){

PORTA=x[ix+1];

delay_for(LATENTA4);

}

if (ix+2<24){

PORTA=x[ix+2];

delay_for(LATENTA4);

}

}

}

}

unsigned int afisya(unsigned char iy){

if (iy<8) return 0x40;

else

if (iy<16) return 0x80;

else

if (iy<24) return 0x00;

}

void afisy(unsigned char iy){

unsigned int i;

unsigned char temp;

if (zoom_crt<ZOOM1){

PORTA=afisya(iy);

pz=1;

temp=y[iy];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA1);

} else

if (zoom_crt<ZOOM2){

pz=2;

PORTA=afisya(iy);

temp=y[iy];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA2);

if ((iy+1)<24){

PORTA=afisya(iy+1);

temp=y[iy+1];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA2);

}

PORTA=0;

PTAD_PTAD=0;

}else

if (zoom_crt<ZOOM3){

pz=3;

PORTA=afisya(iy);

temp=y[iy];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA3);

if ((iy-1)>0){

PORTA=afisya(iy-1);

temp=y[iy-1];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA3);

}

if ((iy+1)<24){

PORTA=afisya(iy+1);

temp=y[iy+1];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA3);

}

}else{

pz=4;

PORTA=afisya(iy);

temp=y[iy];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA4);

if ((iy-2)>0){

PORTA=afisya(iy-2);

temp=y[iy-2];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA4);

}

if ((iy-1)>0){

PORTA=afisya(iy-1);

temp=y[iy-1];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA4);

}

if ((iy+1)<24){

PORTA=afisya(iy+1);

temp=y[iy+1];

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

delay_for(LATENTA4);

}

}

PORTA=0;

temp=0;

if (buzzer_on>0){

temp=temp|0x20;

}

PTAD_PTAD=temp;

}

Ce e inutil trebuie scos :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...