MCP_13_merged
MCP_13_merged
MCP_13_merged
LAB RECORD
DECEMBER 2024
SRI RAMAKRISHNA ENGINEERING COLLEGE
[Educational Service: SNR Sons Charitable Trust]
[Autonomous Institution, Reaccredited by NAAC with ‘A+’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001-2015 Certified and all eligible programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022
CLASS: III B.E CSE & M.Tech CSE (5 Year Int. course) SEMESTER: V
Date:
REGISTER NUMBER
71812201013
Submitted for the V semester B.E and M.Tech . practical examination held on
1
AJEEM KHAN K (71812201013)
Exp. No: 01
8051 ASSEMBLY PROGRAM FOR VARIOUS
Date: ADDRESSING MODES
AIM:
To write an ALP for arithmetic and logical operations of two 8-bit numbers using various
addressing modes.
PROCEDURE:
Start the program.
Move the hexa value to R0 register.
Move the hexa value to R1 register.
Move the value in R0 to the accumulator.
Move the register R1 to accumulator and add.
End the program.
ARITHMETIC OPERATION:
ADDITION:
PROGRAM:
MOV R0,#01H
MOV R1,#02H
MOV A,R0
ADD A,R1
END
OUTPUT:
SUBTRACTION:
AJEEM KHAN K (71812201013)
PROGRAM:
MOV R0,#04H
MOV R1,#02H
MOV A,R1
SUBB A,R0
END
OUTPUT:
MULTIPLICATION:
PROGRAM:
MOV R0,#04H
MOV R1,#02H
MOV A,R0
MOV B,R1
MUL AB
END
OUTPUT:
AJEEM KHAN K (71812201013)
DIVISION:
PROGRAM:
MOV R0,#05H
MOV R1,#02H
MOV A,R0
MOV B,R1
DIV AB
END
OUTPUT:
LOGICAL OPERATION:
AND OPERATION:
AJEEM KHAN K (71812201013)
PROGRAM:
MOV R0,#0C0H
MOV R1,#0F0H
MOV A,R0
ANL A,R1
END
OUTPUT:
LOGICAL OPERATION:
OR OPERATION:
PROGRAM:
MOV R0,#0C0H
MOV R1,#0D0H
MOV A,R0
ORL A,R1
END
OUTPUT:
AJEEM KHAN K (71812201013)
LOGICAL OPERATION:
NOT OPERATION:
PROGRAM:
MOV R0,#0F0H
MOV A,R0
CPL A
END
OUTPUT:
AJEEM KHAN K (71812201013)
LOGICAL OPERATION:
X-OR OPERATION:
PROGRAM:
MOV R0,#0A0H
MOV R1,#0B0H
MOV A,R0
XRL A,R1
END
OUTPUT:
RESULT:
Thus the program to perform arithmetic and logical operations has been executed.
K AJEEM KHAN (71812201013)
Org 00h
mov r0, #10h
mov r1, #20h
mov @r1, a
inc r0
inc r1
djnz r2,l1
end
K AJEEM KHAN (71812201013)
K AJEEM KHAN (71812201013)
AIM:
PROCEDURE:
PROGRAM:
OUTPUT: (BEFORE)
OUTPUT:(AFTER)
AJEEM KHAN K(71812201013)
EX.no:3
8051 ALP TO FIND THE LARGEST / SMALLEST IN A
Date: GIVEN ARRAY
AIM:
To write the ALP to find the largest number from given 'N' numbers.
ALGORITHM:
PROGRAM:
ORG 00H
MOV R2,10H
DEC R2
MOV R0,#20H
MOV A,@R0
MOV R1,#31H
L1:MOV 00,@R1
CJNE A,00,L2
L2:JNC L3
MOV A,@R1
L3:INC R1
DJNZ R2,L1
MOV 60H,A
END
OUTPUT:(BEFORE)
AJEEM KHAN K(71812201013)
OUTPUT:(AFTER)
AJEEM KHAN K(71812201013)
AIM:
To write the ALP to find the smallest number from given 'N' numbers.
ALGORITHM:
PROGRAM:
ORG 00H
MOV R2,10H
DEC R2
MOV R0,#20H
MOV A,@R0
MOV R1,#31H
L1:MOV 00,@R1
CJNE A,00,L2
L2:JC L3
MOV A,@R1
L3:INC R1
DJNZ R2,L1
MOV 70H,A
END
OUTPUT:(BEFORE)
AJEEM KHAN K(71812201013)
OUTPUT:(AFTER)
RESULT:
Thus the ALP to find the smallest and largest number from the N numbers has executed
successfully.
AJEEM KHAN K (71812201013)
Ex. No.:4 8051 C Programming for Timer with Software Delay and Interrupt-
Based Pin Toggling
a) 8051 programming for timer mode 1 and enable/disable a port pin with a delay
Aim:
To write a C program for timer mode 1 and enable/disable a port pin with a delay.
Procedure:
STEP 1: Set Timer 1 in Mode 2 (8-bit auto-reload mode) by configuring the TMOD register.
STEP 2: Load the desired delay value into TH1 (since it's an 8-bit timer, only the high byte is
required).
STEP 3: Start Timer 1 by setting TR1 to 1.
STEP 4: Continuously monitor the TF1 flag (Timer 1 flag) until it's set, indicating the delay has
elapsed.
STEP 5: Stop Timer 1 by setting TR1 to 0.
STEP 6: Clear the TF1 flag.
STEP 7: Reload the initial value into TH1 and repeat from Step 3 if another delay is required.
Program:
#include<reg51.h>
sbit test = P3^0;
void timer_delay()
{
TH0 = 0xFC;
TL0 = 0x74;
TR0 = 1;
while(TF0 == 0);
TR0 = 0;
TF0 = 0;
}
void main()
{
TMOD = 0x01;
while(1)
{
test = ~test;
timer_delay();
}
}
AJEEM KHAN K (71812201013)
Output:
Before execution:
After execution:
AJEEM KHAN K (71812201013)
AIM:
To implement a periodic timer-based interrupt in the 8051 microcontroller to toggle an output
pin at a fixed time interval .
ALGORITHM:
STEP 1: Initialize Timer 1 in Mode 2 (8-bit auto-reload mode) with a 50ms interval. Load the
appropriate value into TH1 for a 50ms delay.
STEP 2: Enable global interrupts and Timer 1 interrupt by configuring the appropriate interrupt enable
registers.
STEP 3: Implement the Timer 1 Interrupt Service Routine (ISR) to toggle an output pin. In the ISR,
reload the timer value into TH1 for the next 50ms interval (though in Mode 2, the value is
automatically reloaded).
STEP 4: In the main function, initialize Timer 1 and enable interrupts by setting TR1 to start the timer.
STEP 5: Enter an infinite loop in the main function. The toggling of the output pin is handled by the
Timer 1 interrupts at 50ms intervals, so the main loop will remain idle, continuously waiting for
interrupts.
Program:
#include <reg51.h>
sbit test = P2^0;
void Timer_init() {
TMOD = 0x02;
TH0 = 0x3E;
TL0 = 0x00;
TR0 = 1;
}
int main(void) {
EA = 1;
ET0 = 1;
Timer_init();
while (1);
}
AJEEM KHAN K (71812201013)
Output:
BEFORE EXECUTION:
AFTER EXECUTION:
Result:
The Timer 1 was successfully configured in Mode 2, and the 50ms interval output pin
toggling was executed and verified through interrupts.
EX NO : 5
8051 C PROGRAMMING FOR PORT HANDLING OPERATIONS
DATE: 22.08.2024
AIM:
ALGORITHM:
PROGRAM:
#include <reg51.h>
void main(void) {
while (1) {
unsigned char x, y;
unsigned char mb = 0x29;
x = mb & 0x0F;
P1 = x | 0x30;
y = mb & 0xF0;
y = y >> 4;
P1 = y | 0x30;
}}
AIM:
To write a c program to toggle P1.7 with a time delay in between each state.
ALGORITHM:
PROGRAM:
#include <reg51.h>
sbit mybit = P1^7;
void delay(unsigned int a);
void main(void) {
while (1) {
mybit = 0;
delay(20);
mybit = 1;
OUTPUT:
AIM:
PROCEDURE:
#include <REG51.H>
void MsDelay(unsigned int);
void main() {
P0 = P1 = P2 = P3 = 0x55;
while (1) {
P0 = ~P0;
P1 = ~P1;
P2 = ~P2;
P3 = ~P3;
MsDelay(1);
}
}
void MsDelay(unsigned int itime) {
unsigned int i, j;
for (i = 0; i < itime; i++) {
for (j = 0; j < 3; j++);
}
}
OUTPUT:
RESULT:
Thus, the port handling in 8051 has been executed successfully.
DATE: 03.09.2024
ALGORITHM:
PROGRAM:
#include <REGX52.H>
#define LED1 P1_5
#define LED2 P1_4
#define LED3 P1_3
void delay(unsigned int count);
void main() {
while (1) {
LED1 = 0; // Turn on LED1
delay(25);
LED1 = 1; // Turn off LED1
delay(25);
}
OUTPUT:
BEFORE EXECUTION:
AFTER EXECUTION:
AIM:
ALGORITHM:
PROGRAM:
if (SW2 == 0) {
while (!SW2);
beep = 0;
delay(25);
beep = 1;
LED0 = 1;
LED1 = 0;
LED2 = 1;
} /* Switch 2 Check */
if (SW3 == 0) {
while (!SW3);
beep = 0;
delay(25);
beep = 1;
LED2 = 0;
LED1 = 1;
LED0 = 1;
} /* Switch 3 Check */
}
}
OUTPUT:
LED 1 LED 2
LED 3
RESULT:
Thus, the 8051 LED interfacing programs has been executed successfully.
DATE: 12.09.2024
AIM:
ALGORITHM:
void lcd_initial(void):
Call the function lcd_command for the following values [0x30, 0x38, 0x01, 0x06, 0x80, 0x0c ].
Hexcode Command
PROGRAM:
#include <REGX52.H>
#define LCD_PORT P0
#define EN P1_0
#define RS P1_2
#define RW P1_1
void lcd_initial(void);
void lcd_command(char);
void lcd_data(char);
void main() {
lcd_initial();
lcd_display(0x80, "SONA K");
lcd_display(0xC0, "CSE FACULTY");
while (1);
}
void lcd_initial(void) {
lcd_command(0x30);
lcd_command(0x30);
lcd_command(0x30);
lcd_command(0x38);
lcd_command(0x01);
lcd_command(0x06);
lcd_command(0x0C);
lcd_command(0x80);
}
OUTPUT:
AIM:
To write the 8051 C program to display different texts based on clicking switches.
ALGORITHM:
void lcd_initial(void):
Call the function lcd_command for the following values [0x30, 0x38, 0x01, 0x06, 0x80, 0x0c].
PROGRAM:
#include <REGX52.H>
#define LCD_PORT P0
#define EN P1_0
#define RS P1_2
#define RW P1_1
#define SW1 P2_0
#define SW2 P2_1
#define SW3 P2_2
#define beep P1_6
void Lcd_Initial(void);
void lcd_command(char);
void lcd_data(char);
void lcd_display(unsigned char locn, const char *dat);
void delay(unsigned int count);
void main() {
P2 = 0x07; // Shift display left
Lcd_Initial();
lcd_display(0x80, "Press Any Switch");
delay(100);
if (SW2 == 0) {
while (!SW2);
beep = 0;
delay(25);
beep = 1;
lcd_display(0x80, "Pressed Switch 2");
} /* Switch 2 Check */
if (SW3 == 0) {
while (!SW3);
beep = 0;
delay(25);
beep = 1;
lcd_display(0x80, "Pressed Switch 3");
} /* Switch 3 Check */
}
}
void Lcd_Initial(void) {
lcd_command(0x30); /* LCD Specification Command */
lcd_command(0x30); /* LCD Specification Command */
lcd_command(0x30); /* LCD Specification Command */
lcd_command(0x38); /* LCD Double Line Display Command */
lcd_command(0x01); /* LCD Display Clear Command */
lcd_command(0x06); /* LCD Auto Increment Location Address Command */
RESULT:
Thus the 8051 LCD interfacing programs has been executed successfully.
DATE: 19.09.2024
AIM:
PROCEDURE:
PROGRAM:
#include <lpc21xx.h>
int main() {
IO1DIR = 0x00FF0000; /* Port1 16-23 as output */
while (1) { /* Infinite loop */
IO1SET = 0x00FF0000; /* Port1 16-23 High */
delay(1000000); /* A delay of 100ms */
OUTPUT:
AIM:
ALGORITHM:
#include <LPC21xx.h>
#include "lcd4bit.h"
while (1);
}
RESULT:
Thus the ARM7 for LED & LCD interface has been executed successfully.
DATE: 26.09.2024
AIM:
ALGORITHM:
PROGRAM:
#include <lpc21xx.h>
int main(void) {
IO0DIR = 0x00010080; /* Set P0.7 and another pin as output */
init_ext(); /* Initialize external interrupt */
while (1); /* Infinite loop */
}
OUTPUT:
Thus , the ARM7 buzzer interfacing program has been executed successfully.
AIM:
To demonstrate the process of LED Blink with Timer using ARM Processor.
PROCEDURE:
PROGRAM:
#include <lpc21xx.h>
void timer_interrupt(void) irq {
T0IR = 0x01; /* Clear interrupt flag */
IO1PIN = (IO1PIN ^ 0x00FF0000) & 0x00FF0000; /* Toggle LEDs on every interrupt */
VICVectAddr = 0x00000000; /* Acknowledge Interrupt */
}
void init_timer(void) {
T0MCR = 0x0003; /* Reset on MR0 & Interrupt on MR0 */
T0PR = 0x00; /* No prescaling */
T0MR0 = 0x00FFFFFF; /* Match value for timer */
int main(void) {
init_timer();
IO1DIR = 0x00FF0000; /* Set LED channel as output */
while (1); /* Infinite loop */
}
OUTPUT:
Thus the ARM7 timer controlling program has been executed successfully.
AIM:
PROCEDURE:
1. The program starts by including the Liquid Crystal library, which is required for
interfacing with the LCD.
2. The Liquid Crystal library is initialized with the pin numbers for Register Select (RS),
Enable (EN), and data pins D4, D5, D6, and D7. These pins are connected to your
Arduino to control the LCD.
3. In the setup function, the LCD's number of columns and rows is specified using lcd.
begin (16, 2). This informs the library that you are using a 16x2 LCD.
4. In the loop function, the following actions are performed:
a. lcd.print("CIRCUIT DIGEST"): This displays "CIRCUIT
DIGEST" on the first line of the LCD.
b. lcd.setCursor(0, 1): This moves the cursor to the second line of the
LCD (line 1) and sets it to the first column (column 0).
f. lcd.setCursor(0, 0): The cursor is moved back to the first line for
the next iteration.
PROGRAM:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to const int rs = 12, en= 11, d4= 5, d5= 4,
//d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since
reset:lcd.print(millis() / 1000);
}
Connection diagram:
Output:
RESULT:
Thus, interfacing a 16x2 LCD with an Arduino is executed and verified successfully