0% found this document useful (0 votes)
20 views9 pages

Microcontroller Report

Microcontroller alarm setting up for vehicle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Microcontroller Report

Microcontroller alarm setting up for vehicle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

CONTENTS

1. INTRODUCTION

2. INTERFACING

3. PROGRAM

4. APPLICATIONS

5. CONCLUSION
INTRODUCTION

INTERFACING LCD TO 8051

LIQUID CRYSTAL DISPLAY

A liquid crystal display is flat panel display or other electronically


modulated optical device that uses the light modulating properties of
liquid crystals combined with polarizers.Liquid crystals do not emit
directly but instead use a backlight or reflector to produce images in
color or monochrome.

The LCD works on the principle of blocking light.While constructing


the LCDs reflected mirror is arranged at the back.An electrode plane is
made of indium-tin-oxide.Which is kept on top and as a polarized glass
with a polarizing fim is also added on the bottom of the device.
INTERFACING LCD TO 8051

Interfacing a 16x2 LCD with an 8051 microcontroller involves


connecting the LCD to the microcontroller and writing appropriate code
to control the display. Below is a step-by-step guide for interfacing an
LCD with the 8051 microcontroller.

Hardware Connections
For a 16x2 LCD, you typically use the 4-bit mode for interfacing. Here's
how you connect the LCD to the 8051
LCD Pinout:
VSS: Ground (0V)
VDD: Power supply (+5V)
VO: Contrast (connected to a potentiometer)
RS: Register Select (connect to P1.0)
RW: Read/Write (connect to Ground for write-only mode)
EN: Enable (connect to P1.1)
D4-D7: Data bus lines (connect to P1.2 to P1.5)
A: Anode (backlight positive, if used)
K: Cathode (backlight negative, if used)
PROGRAM CODE

ASSEMBLY LANGUAGE CODE

ORG 0000H ; Origin, starting address


LJMP MAIN ; Jump to main routine

ORG 0030H ; Define data area

MAIN:
MOV P2, #00H ; Set P2 to 0 (for control lines)
MOV LCD, #00H ; Clear LCD data port

; Initialization sequence
ACALL DELAY
MOV A, #02H ; Function set: 4-bit mode
ACALL LCD_CMD
MOV A, #28H ; Function set: 2-line display, 5x7 font
ACALL LCD_CMD
MOV A, #0CH ; Display on, cursor off
ACALL LCD_CMD
MOV A, #01H ; Clear display
ACALL LCD_CMD
MOV A, #06H ; Entry mode set
ACALL LCD_CMD

; Print string
MOV DPTR, #MSG ; Point to message
PRINT_LOOP:
CLR A
MOV A, @DPTR ; Load character from data pointer
JZ END_PRINT ; If zero, end of string
ACALL LCD_DATA ; Send character to LCD
INC DPTR ; Move to next character
SJMP PRINT_LOOP ; Repeat for next character

END_PRINT:
SJMP $ ; Infinite loop
LCD_CMD:
MOV P2, #00H ; RS = 0, RW = 0 (Command mode)
MOV LCD, A ; Send command to LCD
MOV P2, #01H ; Enable
ACALL DELAY ; Short delay
MOV P2, #00H ; Disable
RET

LCD_DATA:
MOV P2, #01H ; RS = 1, RW = 0 (Data mode)
MOV LCD, A ; Send data to LCD
MOV P2, #01H ; Enable
ACALL DELAY ; Short delay
MOV P2, #00H ; Disable
RET

DELAY:
MOV R1, #250 ; Outer loop
DELAY_LOOP1:
MOV R2, #250 ; Inner loop
DELAY_LOOP2:
DJNZ R2, DELAY_LOOP2
DJNZ R1, DELAY_LOOP1
RET

MSG:
DB 'Hello, World!', 0 ; Message to display
END

EXPLANATION OF CODE

1. *Initialization:* Program starts, clears port P2, and sets up the LCD.
2. *LCD Setup:* Configures the LCD for 4-bit mode, 2 lines, and 5x7
font.
3. *Display Message:* Sends 'Hello, World!' to the LCD.
4. *Command Routine:* Sends commands to the LCD.
5. *Data Routine:* Sends characters to the LCD.
6. *Delay:* Provides timing delays for LCD operations.
C LANGUAGE CODE
#include <reg51.h>

#define LCD PORT1

// Delay function
void delay(unsigned int time) {
while (time--);
}

// Send command to LCD


void lcd_command(unsigned char cmd) {
LCD = cmd; // Send command to data port
P2 = 0x00; // RS = 0, RW = 0 (write mode)
P2 = 0x01; // Enable LCD
delay(1); // Short delay
P2 = 0x00; // Disable LCD
delay(10); // Delay for command execution
}

// Send data to LCD


void lcd_data(unsigned char data) {
LCD = data; // Send data to data port
P2 = 0x01; // RS = 1, RW = 0 (write mode)
P2 = 0x01; // Enable LCD
delay(1); // Short delay
P2 = 0x00; // Disable LCD
delay(10); // Delay for data write
}

// Initialize LCD
void lcd_init(void) {
delay(200); // Power on delay
lcd_command(0x02); // Initialize in 4-bit mode
lcd_command(0x28); // 4-bit, 2-line, 5x7 font
lcd_command(0x0C); // Display on, cursor off
lcd_command(0x01); // Clear display
lcd_command(0x06); // Entry mode set
}

// Print string on LCD


void lcd_print(char *str) {
while (*str) {
lcd_data(*str++); // Print character by character
}
}

// Main function
void main(void) {
lcd_init(); // Initialize LCD
lcd_command(0x80); // Set cursor to start
lcd_print("Hello, World!"); // Print message
while(1); // Infinite loop
}

EXPLANATION OF CODE
1. *#include <reg51.h>* includes 8051-specific definitions.
2. *#define LCD PORT1* assigns PORT1 to the LCD data lines.
3. *delay(unsigned int time)* provides a delay for timing adjustments.
4. *lcd_command(unsigned char cmd)* sends a command to the LCD by
setting the control lines appropriately and toggling the enable pin.
5. *lcd_data(unsigned char data)* sends data to the LCD, similar to
lcd_command but with RS set to 1 for data mode.
6. *lcd_init(void)* initializes the LCD in 4-bit mode, sets it to 2 lines, and
configures display settings.
7. *lcd_print(char *str)* prints a string to the LCD character by character.
8. *main(void)* initializes the LCD, sets the cursor to the start position,
and prints "Hello, World!".
9. *The program runs indefinitely* after displaying the message, ensuring
the text remains on the LCD.
APPLICATIONS

 LEDs are widely used in many applications like in seven


segments.
 They are used in LCD televisions.
 They can be used in computer monitors.
 They are used in instrument panels.
 They are used in aircraft cockpit displays.
 They are used in emergency lights
 They are used in indoor and outdoor signage.

CONCLUSION

The 8051 microcontroller, despite its age, remains a stalwart in the


world of embedded systems and microcontroller applications. Its
enduring legacy can be attributed to its versatility, cost-effectiveness,
and adaptability to various scenarios. As technology continues to
evolve, the 8051’s relevance persists, finding its place in both new and
existing systems. Whether it’s for educational purposes, legacy system
maintenance, or cost-effective solutions, the 8051 microcontroller
continues to prove that age is no barrier to relevance in the ever-
changing landscape of technology.

You might also like