This post is belongs to tutorial on Interfacing LCD with 8051 microcontroller using Mikro c for 8051. I should mention first that Mikro C for 8051 is very good compiler for write embedded C program and generating hex file. In Mikro C for 8051 has lots of inbuilt library program so we can easily write program by calling those library program.

Project Description:

In this simple project “Interfacing LCD with 8051 microcontroller using Mikro c for 8051”, you will find how we can display any text and scroll it in LCD. Here we send the text “NBCAFE” on LCD and scroll it on right side.

In Mikro C for 8051 to Interfacing LCD with 8051 microcontroller, we have to define the port and it’s Pin which is connected to LCD by using “sbit” command. See the example by which we can define the port.

sbit LCD_RS at P2_0_bit;

sbit LCD_EN at P2_1_bit;

sbit LCD_D4 at P2_2_bit;

sbit LCD_D5 at P2_3_bit;

sbit LCD_D6 at P2_4_bit;

sbit LCD_D7 at P2_5_bit;


To know details about the different ports in 8051 microcontroller read my previous post “Ports in 8051 microcontroller”. in bellow you will find the Proteus simulation Circuit diagram of “Interfacing LCD with 8051 microcontroller using Mikro c for 8051”

Interfacing LCD with 8051 microcontroller  

And bellow you will find the complete Embedded C Code written in Mikro C for 8051.

Embedded C Code
// Name : Interfacing LCD with 8051 microcontroller using Mikro c for 8051

// Author : Subham Dutta
// Date : 09-08-14
// Website : www.nbcafe.in
// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connectionschar txt1[] = “NBCAFE”;void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main(){
int i=1;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

while(1) { // Endless loop
Lcd_Out(1,1,txt1); // Write text in first row
Delay_ms(2000);

for(i=1; i<10; i++) { // Move text to the right 7 times
Lcd_Out(1,i,txt1); // Write text in second row
Move_Delay();
Lcd_Cmd(_LCD_CLEAR); // Clear display
}
}
}