Unit-5 All
Unit-5 All
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:
Unit-5 All 1
1. Write the Program:
Use an assembler (e.g., Keil) to convert the .asm file into machine code,
generating a .hex file.
Use a programmer to load the .hex file into the 8051 microcontroller.
Note: Ensure proper hardware connections and configurations before running the
program.
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.
C Code:
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:
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:
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);
}
Explanation:
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:
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:
C Code:
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:
C Code:
#include <LiquidCrystal.h>
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:
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:
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:
Assembly Code:
ORG 0000H
START: MOV P1, #0F0H ; Set rows as outputs, columns as inputs
ACALL SCAN
SJMP START
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