Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16*2 lcd

Status
Not open for further replies.

neo_matrix671

New Member
hi,i'm a beginner at microcontroller.I'm using AT89s52.Currently i'm using keil as a compiler.
Now i need to interface a 16*2 LCD with AT89s52.
so can anyone provide information(Tutorial) on interfacing a 16*2 LCD with AT89s52 with code example.
 
Last edited:
hi,i'm a beginner at microcontroller.I'm using AT89s52.Currently i'm using keil as a compiler.
Now i need to interface a 16*2 LCD with AT89s52.
so can anyone provide information(Tutorial) on interfacing a 16*2 LCD with AT89s52 with code example.

hi,
Look here: **broken link removed**

Google for: AT89s52 to 44780 LCD
 
you can see my incomplete tutorial, it will give you some useful information
LCD Interfacing : TheCollegeRoad, easy pay .. rapid delivery

code for 8051, will also work for your environment

#include <REGX51.H>

#define DATA P2
#define EN P3_0
#define RW P3_1
#define RS P3_2

//#define SCL P3_3
//#define SDA P3_4

sbit rd=P3^3;
sbit wr=P3^4;
sbit intr=P3^5;


#define byte1 144
#define byte2 0
#define byte3 145

void lcd_ini(void);
void delay (int);
void wr_comm();
void wr_data();
void anding (int);
void wait (void);

int unit;
int tenth;
int hundred;
char tosend;
int datas=0;
int inch_count;
char u,t,h;
char ax,bx,cx;
int cm_count;


int x_0=0,x_1=0,x_2=0,x_3=0,x_4=0,x_5=0,x_6=0,x_7=0;
int y_0=0,y_1=0,y_2=0,y_3=0,y_4=0,y_5=0,y_6=0,y_7=0;
int z_0=0,z_1=0,z_2=0,z_3=0,z_4=0,z_5=0,z_6=0,z_7=0;

void main (void)
{int temp=0, temp2=0;
P0=0; P1=0xFF; P2=0; P3=0;


//______________________________adc


intr=1;
rd=1;
wr=1;



//_______________________________

lcd_ini(); //LCD
DATA= 'T';
wr_data();
DATA= 'E';
wr_data();
DATA= 'M';
wr_data();
DATA= 'P';
wr_data();
DATA= '*';
wr_data();
//anding(byte1);
//*************************************************************









//lcd_display_character((char)ax+48, LINE2, 7) ;
//lcd_display_character((char)bx+48, LINE2, 6) ;
//lcd_display_character((char)h+48, LINE2, 5) ;

//*************************************************************
while(1)
{
wr=0;
wr=1;

while(intr==1);
rd=0;

inch_count=P1;
rd=1;

//datas=convert(dat_count);
t=inch_count/10;
u=inch_count-(u*10);
h=inch_count/100;
cx=inch_count-(h*100);
bx=cx/10;
ax=cx%10;

DATA= 'T';
wr_data();
DATA= 'E';
wr_data();
DATA= 'M';
wr_data();
DATA= 'P';
wr_data();
DATA= '=';
wr_data();
tosend=(char)h+48;
DATA= tosend;
wr_data();

tosend=(char)bx+48;
DATA= tosend;
wr_data();

tosend=(char)ax+48;
DATA= tosend;
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
DATA= ' ';
wr_data();
//delay(100);

}
}

void lcd_ini(void)
{
DATA=0x38;
wr_comm();
//delay(1000);
DATA=0x0E;
wr_comm();
//delay(1000);
DATA=0x01;
wr_comm();
//delay(1000);
DATA=0x06;
wr_comm();
//delay(1000);
DATA=0x01;
wr_comm();
}


void wr_comm()
{RS=0;
RW=0;
EN=1;
EN=0;
delay(150);
}

void wr_data()
{RS=1;
RW=0;
EN=1;
EN=0;
delay(150);
}

void delay (int time)
{
int i;
time = time * 1;
for(i=0; i<time; i++)
{}
}

void anding (int byte)
{x_7=(byte)&(128);
x_6=(byte)&(64);
x_5=(byte)&(32);
x_4=(byte)&(16);
x_3=(byte)&(8);
x_2=(byte)&(4);
x_1=(byte)&(2);
x_0=(byte)&(1);
}

void wait (void)
{int p;
for(p=0;p<=100;p++)
{}
}

TheCollegeRoad, easy pay .. rapid delivery
 
You can refer to "8051 microcntroller" by Mazidi.
It contains all the basic codes.

I can provide you the assembly language code
Code:
lcddatabus      equ     80h             ;LCD Data Bus   P0
lcdrs           equ     a7h             ;LCD RS         P2.7
lcden           equ     a6h             ;LCD EN         P2.6
lcd_reg         equ     30h
delreg1         equ     31h
delreg2         equ     32h
;==========================================================
                org 0000h
                call lcdinit
                mov dptr,#msgwelcome
                call lcddisp
here          jmp here
;===============================================================
lcdinit         
                mov lcddatabus,#38h
                call lcdcmd
                mov lcddatabus,#0ch
                call lcdcmd
                mov lcddatabus,#01h
                call lcdcmd
                mov lcddatabus,#06h
                call lcdcmd
                ret
;===============================================================
lcdcmd          clr lcdrs
                setb lcden
                nop
                nop
                clr lcden
                call lcddelay
                ret                        
;===============================================================
lcddata         setb lcdrs
                setb lcden
                nop
                nop
                clr lcden
                call lcddelay
                ret
;===============================================================
lcddelay        mov delreg1,#08             ;LCD
lcddelay1       mov delreg2,#250
                djnz delreg2,$
                djnz delreg1,lcddelay1
                ret
;===============================================================
lcddisp         mov lcddatabus,#01h
                call lcdcmd
                mov lcd_reg,#00h
lcddisp2        mov a,lcd_reg
                movc a,@a+dptr
                cjne a,#'@',lcddisp1
                mov lcddatabus,#c0h
                call lcdcmd
                inc lcd_reg
                jmp lcddisp2
lcddisp1        cjne a,#'$',lcddisp3
                ret
lcddisp3        mov lcddatabus,a
                call lcddata
                jmp lcddisp2
;===============================================================
msgwelcome:     db "  WELCOME TO     @MICROCONTROLLERS$"
          END
 
I have several projects of 1602LCD and 8051, including codes and circuits.
The codes are both C language and assembly language. The circuits are drawed by Proteus, so you need to install it if you want to check the circuit.

If you want this information, just send me an e-mail, zhyh8341@gmail.com
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top