Ex:1(a) LED Blinking Assembly Language Program Using Edsim51d Simulator
//PROGRAM
ORG 0H
START:
SETB P1.0
CALL Delay
CLR P1.0
CALL Delay
SJMP START
Delay:
MOV R2, #5
DelayLoop1:
MOV R1, #5
DelayLoop2:
NOP
DJNZ R1, DelayLoop2
DJNZ R2, DelayLoop1
RET
END
OUTPUT:
Ex: 1(b) 8-Bit Arithmetic Operations 8051microcontroller Using Simulator
//PROGRAM
Addition program
MOV A, #07
MOV B, #03
ADD A, B
MOV R0,A
HERE: SJMP HERE
Subtract program
MOV A, #07
MOV B, #03
SUBB A, B
MOV R1,A
HERE: SJMP HERE
Multiplication program
MOV A,#0FFH
MOV B,#03
MUL AB
MOV R3,A
MOV R4,B
HERE: SJMP HERE
Division program
MOV A,#13
MOV B,#03
DIV AB
MOV R3,A
MOV R4,B
HERE: SJMP HERE
OUTPUT:
Addition:
R0 = 0AH (Decimal 10)
Subtraction:
R1 = 04H (Decimal 4)
Multiplication:
R3 = FDH (Decimal 253)
R4 = 02H (Decimal 2)
Division:
R3 = 06H (Decimal 6) [Quotient]
R4 = 01H (Decimal 1) [Remainder]
Ex: (2) 8-Bit Assembly Language Logical Operations 8051-Microcontroller
//PROGRAM
AND OPERATION PROGRAM
CLR C
MOV A, #07
ANL A, #03
MOV R0, A
HERE: SJMP HERE
OR OPERATION PROGRAM
CLR C
MOV A, #07
ORL A, #03
MOV R1, A
HERE: SJMP HERE
XOR OPERATION PROGRAM
CLR C
MOV A, #07
XRL A, #03
MOV R2, A
HERE: SJMP HERE
1’s COMPLEMENT PROGRAM
CLR C
MOV A,#55H
CPL A
MOV R0,A
HERE: SJMP HERE
2’s COMPLEMENT PROGRAM
CLR C
MOV A, #07
CPL A
INC A
MOV R3,A
HERE: SJMP HERE
OUTPUT
:
1. AND Operation
R0 = 03H (Decimal 3)
2. OR Operation
R1 = 07H (Decimal 7)
3. XOR Operation
R2 = 04H (Decimal 4)
4. 1’s Complement
R0 = AAH (Decimal 170)
5. 2’s Complement
R3 = F9H (Decimal -7)
Ex No:3(a) TEST DATA TRANSFER BETWEEN REGISTER AND MEMORY
//PROGRAM
ORG 00H
MOV A, #54H
MOV 01H, A
MOV R2, A
MOV 07H, A
MOV R1, #00H
MOV 02H,#00H
|HALT: SJMP HALT
OUTPUT:
Register/Memory Finalvalue
A(ACCCUMULATOR) 54
R2 54
R1 0
01H(RAM) 54
07H(RAM) 54
02H(RAM) 0
Ex no:3 (b) COMPARE 2NUMBERS IN 8051
//PROGRAM
ORG 0000H;
MOV
A,#10H;
MOV B,#15H;
CJNE A,B,NOT_EQUAL;
SJMP END_PROGRAM;
NOT_EQUAL;
END_PROGRAM
OUTPUT:
A = 10H (16 in decimal)
B = 15H (21 in decimal)
Since A ≠ B, the program jumps to NOT_EQUAL.
Ex No: 4 (a) 8-Bit Arithmetic Embedded C Programming Using Simulator
//PROGRAM
# include<reg51.h>
void main(void)
{
unsigned char x,y,z, a,b,c, d,e,f, p,q,r; //define variables
//addition
x=0x12; //first 8-bit number
y=0x34; //second 8-bit number
P0=0x00; //declare port 0 as output port
z=x+y; // perform addition
P0=z; //display result on port 0
//subtraction
a=0x12; //first 8-bit number
b=0x34; //second 8-bit number
P1=0x00; //declare port 1 as output port
c=b-a; // perform subtraction
P1=c; //display result on port 1
//multiplication
d=0x12; //first 8-bit number
e=0x34; //second 8-bit number
P2=0x00; //declare port 2 as output port
f=e*d; // perform multiplication
P2=f; //display result on port 2
//division
p=0x12; //first 8-bit number
q=0x34; //second 8-bit number
P3=0x00; //declare port 3 as output port
r=q/p; // perform division
P3=r; //display result on port 3
while(1);
}
OUTPUT:
Operation Hex Calculation Decimal Output Port
Calculation
Addition 0x12 + 0x34 = 0x46 18 + 52 = 70 P0 = 0x46 (70)
Subtraction 0x34 - 0x12 = 0x22 52 - 18 = 34 P1 = 0x22 (34)
Multiplication 0x12 * 0x34 = 18 * 52 = 936 P2 = 0xE8 (Last byte of 936)
0x03E8
Division 0x34 / 0x12 = 0x02 52 / 18 = 2 P3 = 0x02 (2)
Ex No:4(b) 8-Bit Logical Operations Embedded C Programming Using Simulator
//PROGRAM
#include <reg51.h>
void main(void)
{
P0=0x12 & 0x34; //ANDing
P1=0x12 | 0x34; //ORing
P2=0x12 ^ 0x34; //XORing
P3=~0x12; //inversing or NOT
P0=0x12 >> 3; //shifting right 3
P1=0x12 << 4; //shifting left 4
}
OUTPUT:
Operation Hex Calculation Decimal Output Port
Calculation
Addition 0x12 + 0x34 = 0x46 18 + 52 = 70 P0 = 0x46 (70)
Subtraction 0x34 - 0x12 = 0x22 52 - 18 = 34 P1 = 0x22 (34)
Multiplication 0x12 * 0x34 = 18 * 52 = 936 P2 = 0xE8 (Last byte of 936)
0x03E8
Division 0x34 / 0x12 = 0x02 52 / 18 = 2 P3 = 0x02 (2)
ExNo.5(a)INTRODUCTIONTOTHEARDUINOPLATFORM
ArduinoUNO
Ex No:5(b) LED BLINK
//PROGRAM
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(9, OUTPUT);
}
/ / the loop function runs over and over again forever
void loop()
{
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
OUTPUT:
5(c) LED FADE
//PROGRAM
/*
LED Fade Program
This program gradually increases and decreases the brightness of an LED
connected to a PWM-enabled pin (e.g., pin 9) using the analogWrite() function.
*/
int led = 9; // PWM pin to which the LED is connected
int brightness = 0; // Initial brightness of the LED
int fadeAmount = 5; // Amount by which the brightness changes each time
void setup() {
pinMode(led, OUTPUT); // Set the LED pin as OUTPUT
}
void loop()
{
analogWrite(led, brightness); // Set LED brightness using PWM
brightness = brightness + fadeAmount; // Change brightness
// Reverse the fading direction if brightness reaches limits
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30); // Wait for 30 milliseconds to see the fading effect
}
OUTPUT:
Exno.6(a) Communicate Between Arduino and Bluetooth Communication Module
//PROGRAM:
#include<SoftwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2,3); /* (Rx,Tx) */
void setup() {
[Link](9600); /* Define baud rate for software serial communication */
[Link](9600); /* Define baud rate for serial communication */
}
void loop() {
if ([Link]()) /* If data is available on serial port */
{
[Link]([Link]()); /* Print character received on to the serial
monitor */
}
}
OUTPUT:
ExNo:6(b) COMMUNICATION MODULE-ZIGBEE & ARDUINO
//Program
#include <SoftwareSerial.h>
SoftwareSerialzigbeeSerial(2, 3); // RX (pin 1), TX (pin 2)
void setup()
{
// Initialize the Hardware Serial interface (usually connected to your
computer)
[Link](9600); // Use the appropriate baud rate
// Initialize the Software Serial interface (for the Zigbee module)
[Link](9600); // Use the same baud rate as your Zigbee module
}
void loop()
{
// Read data from Zigbee
}
}
if ([Link]())
{
char receivedChar = [Link]();
[Link]("Received: ");
[Link](receivedChar); // Print received data to the Serial Monitor
}
// Send data to Zigbee
[Link]("Hello, Zigbee!"); // Send a message to the Zigbee module
delay(1000); // Add a delay to control message
transmission rate
}
OUTPUT:
h
e
l
l
o
zigbee…
Ex no: 7(a) Introduction to The Raspberry Pi Platform
ExNo:7(b) INTRODUCTION TO PYTHON PROGRAMMING
PROGRAM
//LED:
from machine import Pin
import time
LED = Pin(16, [Link])
while True:
[Link](1)
[Link](1)
[Link](0)
[Link](1)
//RGB:
from machine import Pin
from time import sleep_ms,sleep
r=Pin(16,[Link]) y=Pin(17,[Link])
g=Pin(18,[Link])
while True: [Link](1)
sleep_ms(1000)
[Link](0)
sleep_ms(1000)
[Link](1) sleep(1)
[Link](0) sleep(1)
[Link](1) sleep(1)
[Link](0) sleep(1)
[Link](0) sleep(1)
//SWITCH CONTROLLED LED
from machine import Pin from
time import sleep
led=Pin(16,[Link])
sw=Pin(15,[Link])
while True:
bt=[Link]() if
bt== True:
print("LED ON")
[Link](1) sleep(2)
[Link] (0) sleep(2)
[Link] (1) sleep(2)
[Link](0) sleep(2)
else:
print("LED OFF")
sleep(0.5)
Output
Ex No:8 INTERFACE IR SENSOR WITH RASPBERRY PI
//PROGRAM:
import [Link] as GPIO
import time
sensor=3
[Link]([Link])
[Link](sensor,[Link])
print “IR sensor detected”
print “”
Try:
While True:
If [Link](sensor):
print(“object notdetected”)
While
[Link](Sensor):
[Link](0.2)
Else:
print(“object detected”)
Except KeyboardInterrupt:
[Link]()
Output
ExN0.9 COMMUNICATE ARDUINO AND RASPBERRY PI
//PROGRAM:
void setup()
{
[Link](9600);
}
void loop()
{
[Link] ln(“Hello Pi”);
delay(2000);
}
Output
ExNo: 10 LOG DATA USING CLOUD PLATFORM
//ARDUINO CODE:
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include
"Adafruit_MQTT_Client.h"
#include "DHT.h"
#define WLAN_SSID "YOUR_WIFI_SSID"
#define WLAN_PASS "YOUR_WIFI_PASSWORD"
#define AIO_SERVER "[Link]"
#define AIO_SERVERPORT 1883 // use 8883 for
SSL #define AIO_USERNAME"umaece1982"
#define AIO_KEY "aio_EpaH61HXULkHr4c8izGTucz5Fqoi"
#define DHTPIN D6
#define DHTTYPE DHT11
DHT dht(DHTPIN,
DHTTYPE);
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT,
AIO_USERNAME,
AIO_KEY);
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt,
AIO_USERNAME
"feeds/temperature1");
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME
"feeds/humidity1");
void MQTT_connect();
void setup() {
[Link](115200);
[Link]();
delay(10);
[Link](F("Adafruit MQTT demo"));
[Link](); [Link]();
[Link]("Connecting to ");
[Link](WLAN_SSID);
[Link](WLAN_SSID, WLAN_PASS);
while ([Link]() != WL_CONNECTED) {
delay(500);
[Link](".");
}
[Link]();
[Link]("WiFi connected");
[Link]("IP address: "); [Link]([Link]());
}
uint32_t x=0;
void loop() {
MQTT_connect();
float h = [Link]();
float t = [Link]();
[Link](F("\nTemperature:
")); [Link](t);
[Link](F("\nHumidity: "));
[Link](h);
[Link](t);
[Link](h);
delay(60000);
}
void MQTT_connect()
{ int8_t ret;
if ([Link]()) {
return;
}
[Link]("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = [Link]()) != 0) { // connect will return 0 for connected
[Link]([Link](ret));
[Link]("Retrying MQTT connection in 5 seconds...");
[Link]();
delay(5000); // wait 5
seconds retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
[Link]("MQTT Connected!");}
OUTPUT:
Ex no.11 Log Data using Raspberry PI and upload it to the cloud platform
\\Program
from machine import Pin, I2C, ADC
fromutime import sleep_ms
from pico_i2c_lcd import I2cLcd import
time
import network
importBlynkLib
adc = [Link](4)
i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR=[Link]()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)
wlan = [Link]()
[Link](True)
[Link]("Wifi_Username","Wifi_Password")
BLYNK_AUTH = 'Your_Token'
# connect the network wait =
10
while wait > 0:
[Link]() < 0 or [Link]() >= 3: break
wait -= 1
print('waiting for connection...')
[Link](1)
Output
waiting for connection...
connected
IP: [Link]
Connected to Blynk
Temperature : 27.5 C
Uploading to Cloud...
Temperature : 27.8 C
Uploading to Cloud...
Ex No.12 Design an IOT-based system
//PROGRAM:
import time
import network
import BlynkLib
from machine import Pin
# LED setup
led = Pin(16, [Link])
# WiFi connection
wlan = [Link](network.STA_IF)
[Link](True)
[Link]("Wifi_Username", "Wifi_Password")
print("Connecting to WiFi...")
while not [Link]():
[Link](1)
print("Connected")
print("IP:", [Link]()[0])
# Blynk authentication
BLYNK_AUTH = "Your_Token"
blynk = [Link](BLYNK_AUTH)
print("Connected to Blynk")
# Virtual Pin V0 handler
@[Link]("V0")
def v0_write_handler(value):
if int(value[0]) == 1:
[Link](1)
print("LED ON")
else:
[Link](0)
print("LED OFF")
# Run Blynk
while True:
[Link]()Output
Output
Connecting to WiFi...
Connected
IP: [Link]
Connected to Blynk
LED ON
LED OFF
LED ON