Tutorial Microcontroller MCS-51 ATMEL ISP
 

 

Super MCS51 Trainer

Standart MCS51 Trainer

Standart AVR Trainer

Programmer USBASP

Standart ARM Trainer

 

 

4.1. Writing "A" to LCD Character

In this lesson, you can try to write "A" in first line of LCD Character.



Step 1st
Build the circuit as shown in figure 2.11. As you seen on figure 2.11. P0.0 trough P0.7 is connected to DB0 - DB7,and P3.5, P3.7. is connected to RS and EN each. Remember, that all we want to do with this lesson is write " A", in the first line of LCD Character

Step 2nd
In this step, you must tipe the assembly program to make your LCD Character shown the word, we assume that you have already known the editor, we used MIDE-51 to edit the program.

#include <AT89X52.h>
#include <string.h>
#include <stdio.h>
#define rs P3_5
#define en P3_7
char buf[8];
float myfloat;
//
void delay_ms(unsigned int timedelay)
{
unsigned int x;
for (x=0;x<timedelay;x++);
}
//
void write_lcd(unsigned char dat)
{
P0=dat;
en=1;
delay_ms(2);
en=0;
}
void cmd_lcd(unsigned char cmd)
{
           rs=0;
           write_lcd(cmd);
}
void disp_lcd(unsigned char c)
{
           rs=1;
           write_lcd(c);
}
void init_lcd(void)
{
           cmd_lcd(0x02);
           cmd_lcd(0x38);
           cmd_lcd(0x01);
           cmd_lcd(0x0e);
           cmd_lcd(0x0c);
           cmd_lcd(0x06);
           cmd_lcd(0x80);
}
           //
void str_lcd(unsigned char *s)
{
           while(*s)
           disp_lcd(*s++);
}
           //
main()
{
           init_lcd();
           cmd_lcd(0x80); 
           disp_lcd(0x30+0);
           cmd_lcd(0xCF); 
           str_lcd("A"); 
 while(1)
 { 
 }
}
         

Step 3rd
Safe your assembly program above, and name it with lcd1.asm (for example) Compile the program that you have been save by using KEIL, see the software instruction.

Step 4th
Download your hex file ( lcd1.hex ) into the microcontroller by using Microcontroller ISP software, see the instruction.After download this hex file you'll see the action of the 7 segmen( of course if your cable connection and your program are corrected ).

4.2. Writing text LCD Character 2x16

#include <AT89X52.h>
#include <string.h>
#include <stdio.h>
#define rs P3_5
#define en P3_7
char buf[8];
float myfloat;
//
void delay_ms(unsigned int timedelay)
{
unsigned int x;
for (x=0;x<timedelay;x++);
}
//
void write_lcd(unsigned char dat)
{
P0=dat;
en=1;
delay_ms(2);
en=0;
}
void cmd_lcd(unsigned char cmd)
{
           rs=0;
           write_lcd(cmd);
}
void disp_lcd(unsigned char c)
{
           rs=1;
           write_lcd(c);
}
void init_lcd(void)
{
           cmd_lcd(0x02);
           cmd_lcd(0x38);
           cmd_lcd(0x01);
           cmd_lcd(0x0e);
           cmd_lcd(0x0c);
           cmd_lcd(0x06);
           cmd_lcd(0x80);
}
           //
void str_lcd(unsigned char *s)
{
           while(*s)
           disp_lcd(*s++);
}
           //
main()
{
           init_lcd();
           cmd_lcd(0x80); 
           str_lcd("Welcome To"); 
           cmd_lcd(0xC0); 
           str_lcd(“Lab Mikro”); 
 while(1)
 { 
 }
}
   

4.3. Writing floating point to LCD Character 2x16

#include <AT89X52.h>
#include <string.h>
#include <stdio.h>
#define rs P3_5
#define en P3_7
char buf[8];
float myfloat;
//
void delay_ms(unsigned int timedelay)
{
unsigned int x;
for (x=0;x<timedelay;x++);
}
//
void write_lcd(unsigned char dat)
{
P0=dat;
en=1;
delay_ms(2);
en=0;
}
void cmd_lcd(unsigned char cmd)
{
           rs=0;
           write_lcd(cmd);
}
void disp_lcd(unsigned char c)
{
           rs=1;
           write_lcd(c);
}
void init_lcd(void)
{
           cmd_lcd(0x02);
           cmd_lcd(0x38);
           cmd_lcd(0x01);
           cmd_lcd(0x0e);
           cmd_lcd(0x0c);
           cmd_lcd(0x06);
           cmd_lcd(0x80);
}
           //
void str_lcd(unsigned char *s)
{
           while(*s)
           disp_lcd(*s++);
}
           //
main()
{
           init_lcd();
           myfloat=(float)40/7;
           cmd_lcd(0x00|0x80); 
           str_lcd("Ex. Float = 40/7"); 
           sprintf (buf, "%f",myfloat);
           cmd_lcd(0x00|0xC0); 
           str_lcd(buf); 
 while(1)
 { 
 }
}