Lab Important Question1
Lab Important Question1
Procedure:
Code:
#include <reg51.h>
void main() {
Expected Output:
• P1 = 40
• P2 = 375
2. Write a program to transfer the data between two registers
Procedure:
Code (Assembly):
LOOP:
MOV A, R0 ; Move R0 to A
INC R0 ; Increment R0
Expected Output:
Port 1 will sequentially output values from 0x30 to 0x35.
Procedure:
Code (Assembly):
LOOP:
Expected Output:
Port 2 outputs values from 0x30 to 0x35 sequentially.
Procedure:
• Perform subtraction and division manually (since 8051 lacks division instruction, use
loop-based division).
Code:
#include <reg51.h>
void main() {
// Subtraction
difference = num1 - num2;
quotient++;
while(1);
Expected Output:
Procedure:
Code:
#include <reg51.h>
void main() {
while(1);
Expected Output:
Procedure:
Code (Assembly):
MOV A, #05H
MOV B, #03H
MUL AB
Expected Output:
• R1 = 0x2A (42)
Procedure:
Code:
#include <reg51.h>
void main() {
P2 = or_op; // OR result
while(1);
Expected Output:
• P1 = 0x24
• P2 = 0xBD
• P3 = 0x99
• P0 = 0x5A
Procedure:
EQUAL:
SJMP END
NOT_EQUAL:
END:
Expected Output:
• P1 = 0 (because 42 != 48)
Procedure:
Code:
#include <reg51.h>
void main() {
P1 = 1; // num1 greater
P1 = 2; // num2 greater
} else {
P1 = 0; // Equal
while(1);
Expected Output:
Explanation:
Arduino is an open-source microcontroller platform easy for beginners. It uses simplified C++
with libraries and IDE for quick prototyping. The code has two main functions: setup() runs
once, and loop() runs repeatedly.
void setup() {
void loop() {
11. Write a program to interface any one sensor with Raspberry Pi.
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
print(f'Temp={temperature:0.1f}*C Humidity={humidity:0.1f}%')
else:
Example: Using MQTT to publish data to cloud (e.g., AWS IoT or HiveMQ)
broker = "broker.hivemq.com"
port = 1883
topic = "sensor/data"
client = mqtt.Client()
client.connect(broker, port)
data = '{"temperature": 25, "humidity": 60}'
client.publish(topic, data)
client.disconnect()
Procedure:
• Use sensors to monitor air quality, traffic, lighting, and waste management.
14. How to log the data in Raspberry Pi and upload the data in cloud platform.
Procedure:
import time
import csv
import requests
def read_sensor():
return 25, 60
while True:
Procedure:
Arduino Code:
void setup() {
Serial.begin(9600);
void loop() {
if(Serial.available() > 0) {
Python Code:
import serial
import time
arduino = serial.Serial(port='COM3', baudrate=9600, timeout=1)
data_to_send = 10
arduino.write(bytes([data_to_send]))
response = arduino.read()
arduino.close()