0% found this document useful (0 votes)
0 views8 pages

Unit-5 All

The document provides detailed instructions and assembly code for interfacing various components (LEDs, LCDs, buzzers, switches, and keypads) with the 8051 microcontroller and Arduino. It includes steps for creating, assembling, and running assembly language programs, as well as C code examples for Arduino projects. Each section explains the connections, code functionality, and necessary delays for proper operation.

Uploaded by

abhishek ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

Unit-5 All

The document provides detailed instructions and assembly code for interfacing various components (LEDs, LCDs, buzzers, switches, and keypads) with the 8051 microcontroller and Arduino. It includes steps for creating, assembling, and running assembly language programs, as well as C code examples for Arduino projects. Each section explains the connections, code functionality, and necessary delays for proper operation.

Uploaded by

abhishek ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Unit-5 All

1. LED Interfacing with 8051 Microcontroller


(Assembly Language)
Description:
Interfacing an LED with the 8051 microcontroller involves connecting the LED to
one of the port pins (e.g., P2.0) and toggling the pin to turn the LED on and off.
Assembly Code:

ORG 0000H
START: SETB P2.0 ; Turn ON LED connected to P2.0
ACALL DELAY
CLR P2.0 ; Turn OFF LED
ACALL DELAY
SJMP START ; Repeat
DELAY: MOV R1, #255
D1: MOV R2, #255
D2: DJNZ R2, D2
DJNZ R1, D1
RET
END

Explanation:

SETB P2.0 : Sets P2.0 high, turning the LED on.

CLR P2.0 : Clears P2.0, turning the LED off.

DELAY : Provides a time delay using nested loops.

2. Steps for Creating, Assembling, and Running an


Assembly Language Program
Steps:

Unit-5 All 1
1. Write the Program:

Use an editor (e.g., Notepad) to write the assembly code.

Save the file with a .asm extension.

2. Assemble the Program:

Use an assembler (e.g., Keil) to convert the .asm file into machine code,
generating a .hex file.

3. Load the Program:

Use a programmer to load the .hex file into the 8051 microcontroller.

4. Run the Program:

Power the microcontroller and observe the program's operation.

Note: Ensure proper hardware connections and configurations before running the
program.

3. LCD Interfacing with 8051 Microcontroller


Description:
A 16x2 LCD can be interfaced with the 8051 microcontroller to display characters.
The LCD requires control signals (RS, RW, EN) and data lines (D0–D7).

Connections:

RS → P2.0

RW → P2.1

EN → P2.2

D0–D7 → P1.0–P1.7

Assembly Code:

; Initialize LCD
MOV P2, #00H
ACALL CMD
; Send data to LCD
MOV P2, #DATA

Unit-5 All 2
ACALL DATA
; Subroutines for CMD and DATA would be defined accordingly

Explanation:

Commands and data are sent to the LCD by setting RS and RW appropriately
and toggling EN.

Proper delays are necessary between commands and data writes.

4. C Program to Interface a Single LED with Arduino


Uno
Description:
Control an LED connected to Arduino Uno using digital write operations.

C Code:

const int ledPin = 13;

void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
}

void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for a second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for a second
}

Explanation:

pinMode() sets the LED pin as output.

digitalWrite() controls the LED state.

delay() creates a visible blink effect.

Unit-5 All 3
5. Embedded C Code for Interfacing RGB LED to
Arduino
Description:
Control an RGB LED by varying the intensity of red, green, and blue components.

C Code:

const int redPin = 9;


const int greenPin = 10;
const int bluePin = 11;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
}

void setColor(int red, int green, int blue) {


analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Explanation:

analogWrite() sets the intensity of each color component.

setColor() function simplifies setting RGB values.

Unit-5 All 4
6. Buzzer Interface to Arduino Uno with C Code
Description:
Control a buzzer connected to Arduino Uno to produce sound.

C Code:

const int buzzerPin = 8;

void setup() {
pinMode(buzzerPin, OUTPUT);
}

void loop() {
digitalWrite(buzzerPin, HIGH); // Turn buzzer on
delay(1000); // Wait for a second
digitalWrite(buzzerPin, LOW); // Turn buzzer off
delay(1000); // Wait for a second
}

Explanation:

digitalWrite() controls the buzzer state.

delay() creates an audible beep pattern.

7. Switch Interface to Arduino Uno to Turn on an LED


with Code
Description:
Use a push-button switch to control an LED on Arduino Uno.

C Code:

const int buttonPin = 2;


const int ledPin = 13;
int buttonState = 0;

Unit-5 All 5
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
}

Explanation:

digitalRead() reads the button state.

digitalWrite() sets the LED state based on button input.

8. Embedded C Program to Interface an LCD with


Arduino Uno
Description:
Display text on a 16x2 LCD using Arduino Uno.

C Code:

#include <LiquidCrystal.h>

// Initialize the library with the numbers of the interface pins


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Hello, World!"); // Print a message to the LCD

Unit-5 All 6
}

void loop() {
// Nothing to do here
}

Explanation:

LiquidCrystal library simplifies LCD control.

lcd.begin() initializes the display.

lcd.print() writes text to the LCD.

9. Serial Communication Programming in Arduino with


Examples
Description:
Use serial communication to send and receive data between Arduino and a
computer.

C Code:

void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
}

void loop() {
Serial.println("Hello from Arduino!");
delay(1000); // Wait for a second
}

Explanation:

Serial.begin() initializes serial communication.

Serial.println() sends data to the serial monitor.

delay() controls the frequency of messages.

Unit-5 All 7
10. Interfacing a 4x4 Matrix Keypad with 8051 and
Assembly Language Program
Description:
Scan a 4x4 matrix keypad to detect key presses using the 8051 microcontroller.
Connections:

Rows connected to P1.0–P1.3

Columns connected to P1.4–P1.7

Assembly Code:

ORG 0000H
START: MOV P1, #0F0H ; Set rows as outputs, columns as inputs
ACALL SCAN
SJMP START

SCAN: ; Implement scanning routine here


RET
END

Explanation:

Rows are driven low one at a time while reading columns to detect key
presses.

Debouncing and key mapping are handled within the SCAN subroutine.

Unit-5 All 8

You might also like