[go: up one dir, main page]

0% found this document useful (0 votes)
11 views57 pages

MCP_13_merged

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 57

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

LAB RECORD

ACADEMIC YEAR: 2024 - 2025

Subject: 20EC252 MICROCONTROLLERS AND PROGRAMMING

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

Department of Computer Science and Engineering

CLASS: III B.E CSE & M.Tech CSE (5 Year Int. course) SEMESTER: V

Certified that this is the bonafide record of work done by


Mr. / Ms. AJEEM KHAN K in the 20ECS252

MICROCONTROLLER AND PROGRAMMING of this institution for V Semester

during the academic year 2024 - 2025.

Faculty In-Charge Professor & Head

Date:

REGISTER NUMBER
71812201013

Submitted for the V semester B.E and M.Tech . practical examination held on

Internal Examiner Subject Expert


INDEX
Exp.
Date Name of the experiment
No.
1. 8051 Assembly Language Programming using various
addressing modes
25/07/2024
a. Addition & Subtraction of two 8 bit numbers
25/07/2024
b. Multiplication & Division of two 8 bit numbers
25/07/2024
c. Logical AND & OR of two 8 bit numbers
25/07/2024
d. Logical NOT & XOR of two 8 bit numbers

2. 8051 ALP for data transfer between memory blocks


01/08/2024 Transfer the block of data between two Memorylocations
a.
01/08/2024
b. Exchange the block of data between locations

3. 8051 ALP for data search in numbers


08/08/2024 ALP Program for finding largest number of given N
a.
numbers
08/08/2024 ALP Program for finding smallest number of given N
b.
numbers
4. 8051 C programming for Timer
10/08/2024 8051 programming for timer mode 1 and enable/disable
a.
a port pin with a delay
10/08/2024 8051 programming with timer-based interrupt to toggle
b.
an output pin at a fixed time interval
10/08/2024 Universal Asynchronous Receiver Transmitter (UART)
c.
programming using 8051
5. 8051 C programming for port handling operations
22/08/2024
a. To display ASCII number in a port
22/08/2024
b. I/O port programming with delay
22/08/2024 I/O port programming to toggle between two or moreports
c.

6. 8051 C programming for interfacing actuators and sensors


03/09/2024
a. Blinking the LED with some delay
Exp.
Date Name of the experiment
No.
03/09/2024 8051 programming to interface with LED with switchcontrol
b.

7. 8051 C programming for interfacing output unit


12/09/2024
a. Display the input text in LCD
12/09/2024
b. LCD with switch control
19/09/2024
8. ARM7 programming to interface LED and LCD
26/09/2024
9. ARM7 programming for buzzer interface
10/10/2024
10. ARM7 programming for Timer controlling operation
10/10/2024
CBS Interfacing 16X2 LCD with Arduino

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 r2, #03h


l1: mov a, @r0

mov @r1, a
inc r0
inc r1

djnz r2,l1
end
K AJEEM KHAN (71812201013)
K AJEEM KHAN (71812201013)

b. Exchange the block of data between locations

AIM:

To write an ALP for exchange/swapping of data between two memory locations.

PROCEDURE:

Step 1: Get the initial location of block 1.


Step 2: Get the initial location of block 2.
Step 3: Initialize a counter register to number of elements in memory.
Step 4: Get the content of block 1 in acc. Step 5:
Move it to B.
Step 6: Get the content of block 2 in acc.
Step 7: Move the content of B to block 2.
Step 8: Move the content of acc to block 1.
Step 9: Increment location of block 1.
Step 10: Increase location of block 2.
Step 11: Decrease count.
Step 12: Repeat the steps 4 to 12 until counter becomes 0. Step 13:
End

PROGRAM:

mov r0, #10h


mov r1, #20h
mov r2, #06h
l1: mov a, @r0
mov b,a
mov a,@r1
mov @r1,b
mov @r0,a
inc r0
inc r1
djnz r2,l1
end
K AJEEM KHAN (71812201013)

OUTPUT: (BEFORE)

OUTPUT:(AFTER)
AJEEM KHAN K(71812201013)

EX.no:3
8051 ALP TO FIND THE LARGEST / SMALLEST IN A
Date: GIVEN ARRAY

A) ALP Program for finding largest number of given N numbers

AIM:
To write the ALP to find the largest number from given 'N' numbers.

ALGORITHM:

o Start at memory location 00H (ORG 00H).


o Load register R2 with the value stored at memory location 50H.
o Decrease the value in R2 by 1.
o Load register R0 with immediate value 60H (starting address for data access).
o Load register A (Accumulator) with the value from memory location pointed by R0.
o Load register R1 with immediate value 61H (destination address).
o Start Loop (L1):Move the contents of memory location pointed by R1 to memory
location 00H.
o Use the CJNE (Compare and Jump if Not Equal) instruction to compare the value in
A (Accumulator) with the value stored in memory location 00H. If they are not equal,
jump to L2.
o If the previous comparison results in no carry (JNC), jump to label L3.
o Load the Accumulator A with the value from memory location pointed by R1.
o Increase the value of R1 to point to the next memory location.
o Decrease R2 by 1 and repeat the loop (from label L1) until R2 becomes zero.
o After the loop finishes, store the final value of Accumulator A into memory location
70H.
o Terminate the program with the END directive.
AJEEM KHAN K(71812201013)

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)

B) ALP Program for finding smallest number of given N numbers

AIM:
To write the ALP to find the smallest number from given 'N' numbers.

ALGORITHM:

o Set the starting memory address to 00H using ORG 00H.


o Load register R2 with the value 50H (representing the number of values to compare).
o Decrement R2 by 1 to prepare for loop control.
o Load register R0 with the starting memory address 60H (starting point for the list of
values).
o Load the first value from memory location 60H into the Accumulator (A). This will
be treated as the smallest number initially.
o Load register R1 with 61H to point to the next memory address for comparison.
o Move the value from the memory location pointed by R1 into memory location 00H
temporarily for comparison.
o Compare the value in the Accumulator (A) with the value stored in 00H.
o If the value in A is smaller or equal to the value in 00H, skip the update step.
o If the value in A is greater than the value in 00H, set A to the smaller value from R1
(using the JC instruction).
o If a smaller value is found (i.e., the carry is set), move the new smaller value into the
Accumulator (A).
o Increment R1 to point to the next memory location for the next comparison.
o Decrement R2 by 1 and check if it's zero. If it's not zero, jump back to step 4 to
continue the comparison loop. If it is zero, exit the loop.
o Once the loop finishes, the smallest value will be in the Accumulator (A). Store this
value into memory location 70H.
o The program ends after storing the smallest value.
AJEEM KHAN K(71812201013)

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)

b) ALP Program for finding smallest number of given N numbers

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;
}

void Timer0_ISR() interrupt 1 {


test = ~test;
TH0 = 0x3E;
}

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

a) To display the ASCII number in a port

AIM:

To write the 8051 C program to display ASCII value in a port.

ALGORITHM:

1. Start the program.


2. Declare required headers and the value of mb to 29.
3. To do calculation for the lower 4 nibble do AND operation with 0F.
4. Add 30 to the lower nibble by doing OR operation and display in port P1.
5. To do calculation for the upper 4 nibble do AND operation with F0.
6. Add 30 to the upper nibble by doing OR operation.
7. Shift the value in y by 4 places and display in port P1.
8. Stop the program.

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;
}}

AJEEM KHAN K - 71812201013


OUTPUT:

b) I/O programming with Delay

AIM:

To write a c program to toggle P1.7 with a time delay in between each state.

ALGORITHM:

1. Start the program


2. Include the standard header file for 8051 MCU [reg52.h].
3. Let’s assign P1.7thbitto a variable (mybit).
4. Set mybit=0, this will reset the bit at P1.7.
5. Call the delay function.
6. Set mybit=1,this will set the bit at P1.7
7. Call the delay function.

PROGRAM:

#include <reg51.h>
sbit mybit = P1^7;
void delay(unsigned int a);
void main(void) {
while (1) {
mybit = 0;
delay(20);
mybit = 1;

AJEEM KHAN K - 71812201013


delay(20);
}
}
void delay(unsigned int a) {
unsigned int i, j;
for (i = 0; i < a; i++) {
for (j = 0; j < 50; j++);
}
}

OUTPUT:

c) 8051 I/O port programming to toggle between two or more ports

AIM:

To write a c program to toggle between two or more ports.

PROCEDURE:

1. Start the program.


2. Include the standard header file for 8051 MCU [reg52.h].
3. Load the initial value to all the ports P0,P1,P2,P3.
4. Take complement of values in the port to get the toggled bits.
5. Call the delay function.
6. Stop.

AJEEM KHAN K - 71812201013


PROGRAM:

#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:

BEFORE TOGGLING :– VALUE = 55H

AJEEM KHAN K - 71812201013


AFTER TOGGLING :– VALUE = AAH

RESULT:
Thus, the port handling in 8051 has been executed successfully.

AJEEM KHAN K - 71812201013


EX NO : 6
8051 C PROGRAMMING FOR INTERFACING LED

DATE: 03.09.2024

a) LED without switch


AIM:

To demonstrate the process of blinking LED without switch.

ALGORITHM:

1. Create a new Project.


2. Select the microcontroller Atmel>>AT89C52
3. Enter the source code.
4. Save it
5. Adding Hex file to the output
6. Then Compile it. Click Project>>Build Target or F7
7. The hex file will be generated in your Project Folder.

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);
}

AJEEM KHAN K - 71812201013


}
void delay(unsigned int count) {
int x, y;
for (x = 0; x < count; x++) {
for (y = 0; y < 1275; y++);
}
}

OUTPUT:

BEFORE EXECUTION:

AFTER EXECUTION:

AJEEM KHAN K - 71812201013


b) LED with switch

AIM:

To demonstrate the process of blinking LED with switch.

ALGORITHM:

1. Start the program.


2. Include the required header files and the ports for LEDs, Enable pin (EN), Register Select pin (RS)
,switches (SW) & Beep.
3. In the main() ,run an infinite while loop for continuous control of switches.
4. If a particular Switch is pressed, a beep sound for delay(1) is made & the corresponding LED will
be switched on.
5. In delay(),Declare two unsigned variables.
6. Declare two for loops to make the led0 to blink [for(x=0;x<count;x++) for(y=0;y<1275;y++);]
7. Stop the program.

PROGRAM:

#include <REGX52.H> /* Header File */


#define EN P1_0
#define RS P1_2

#define SW1 P2_0


#define SW2 P2_1
#define SW3 P2_2
#define beep P1_6
#define LED0 P1_5
#define LED1 P1_4
#define LED2 P1_3

void delay(unsigned int count);

AJEEM KHAN K - 71812201013


void main() {
while (1) {
if (SW1 == 0) {
while (!SW1);
beep = 0;
delay(25);
beep = 1;
LED0 = 0;
LED1 = 1;
LED2 = 1;
} /* Switch 1 Check */

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 */
}
}

AJEEM KHAN K - 71812201013


void delay(unsigned int count) {
int x, y;
for (x = 0; x < count; x++) {
for (y = 0; y < 1275; y++);
}
}

OUTPUT:

LED 1 LED 2

LED 3

RESULT:

Thus, the 8051 LED interfacing programs has been executed successfully.

AJEEM KHAN K - 71812201013


EX NO : 7
8051 C PROGRAMMING FOR INTERFACING LCD

DATE: 12.09.2024

a) LCD without switch

AIM:

To write the 8051 C program to display text in LCD without switch.

ALGORITHM:

1. Start the program.


2. Include the required header files and the ports for LCD display, Enable pin (EN), Register Select
pin (RS) and ead/write pin(RW).
3. In the main() ,Call the required functions for initializing and displaying the data with an infinite
while loop for continuously displaying data.
4. Stop the program.

void lcd_initial(void):

Call the function lcd_command for the following values [0x30, 0x38, 0x01, 0x06, 0x80, 0x0c ].

Hexcode Command

30 1 Line, 5x7 matrix


38 2 lines and 5×7 matrix
01 Clear display screen
06 Increment cursor (shift cursor to right)
0C Display on, cursor off
80 Force cursor to beginning (1st line)
C0 Force cursor to beginning (2nd line)

AJEEM KHAN K - 71812201013


void lcd_command(char value):

1. Declare RW=0, RS=0, EN=1, LCD_PORT=value.


2. Call the delay function [delay(1)].
3. Declare EN = 0.

void lcd_data(char value):

1. Declare RW=0, RS=1, EN=1, LCD_PORT=value.


2. Call the delay function [delay(1)].
3. Declare EN = 0.

void lcd_display(unsigned char locn,const char *dat):

1. Call the function lcd_command(locn).


2. Inside the infinite while loop call the function lcd_data(*dat) and do dat++.

void delay(unsigned int count):

1. Declare two unsigned variables.


2. Declare two for loops to make the led0 to blink [for(x=0;x<count;x++)for(y=0;y<1275;y++);]

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);

AJEEM KHAN K - 71812201013


void lcd_display(unsigned char locn, const char *dat);
void delay(unsigned int count);

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);
}

void lcd_command(char value) {


RW = 0;
RS = 0;
EN = 1;
LCD_PORT = value;
delay(1);
EN = 0;
}

void lcd_data(char value) {


RW = 0;
RS = 1;

AJEEM KHAN K - 71812201013


EN = 1;
LCD_PORT = value;
delay(1);
EN = 0;
}

void lcd_display(unsigned char locn, const char *dat) {


lcd_command(locn);
while (*dat != '\0') {
lcd_data(*dat);
dat++;
}
}

void delay(unsigned int count) {


int x, y;
for (x = 0; x < count; x++) {
for (y = 0; y < 1275; y++);
}
}

OUTPUT:

AJEEM KHAN K - 71812201013


b) LCD with switch

AIM:

To write the 8051 C program to display different texts based on clicking switches.

ALGORITHM:

1. Start the program.


2. Include the required header files and the ports for LCD display, Enable pin (EN), Register Select
pin (RS) and Read/write pin(RW) and switches (SW).
3. In the main() ,Call the required functions for initializing & displaying the text.
4. Run an infinite while loop for continuous control of switches.
5. If a particular Switch is pressed, a beep sound for delay(1) is made & the corresponding message
is displayed on the LCD display.
6. Stop the program.

void lcd_initial(void):

Call the function lcd_command for the following values [0x30, 0x38, 0x01, 0x06, 0x80, 0x0c].

void lcd_command(char value):

1. Declare RW=0, RS=0, EN=1, LCD_PORT=value.


2. Call the delay function [delay(1)]. Step 3: Declare EN = 0.

void lcd_data(char value):

1. Declare RW=0, RS=1, EN=1, LCD_PORT=value.


2. Call the delay function [delay(1)].
3. Declare EN = 0.

AJEEM KHAN K - 71812201013


void lcd_display(unsigned char locn,const char *dat):

1. Call the function lcd_command(locn).


2. Inside the infinite while loop call the function lcd_data(*dat) and do dat++.

void delay(unsigned int count):

1. Declare two unsigned variables.


2. Declare two for loops to make the led0 to blink [for(x=0;x<count;x++)for(y=0;y<1275;y++);]

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);

AJEEM KHAN K - 71812201013


while (1) {
if (SW1 == 0) {
while (!SW1);
beep = 0;
delay(25);
beep = 1;
lcd_display(0x80, "Pressed Switch 1");
} /* Switch 1 Check */

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 */

AJEEM KHAN K - 71812201013


lcd_command(0x0C); /* LCD Display ON Command */
}

void lcd_command(char value) {


RW = 0; /* Write Process */
RS = 0; /* Command Register Selection */
EN = 1; /* Enable Set */
LCD_PORT = value;
delay(1);
EN = 0; /* Enable Clear */
}
void lcd_data(char value) {
RW = 0; /* Write Process */
RS = 1; /* Data Register Selection */
EN = 1; /* Enable Set */
LCD_PORT = value;
delay(1);
EN = 0; /* Enable Clear */
}
void lcd_display(unsigned char locn, const char *dat) {
lcd_command(locn); /* LCD Location Address */
while (*dat != '\0') {
lcd_data(*dat);
dat++;
}
}
void delay(unsigned int count) {
int x, y;
for (x = 0; x < count; x++) {
for (y = 0; y < 1275; y++);
}
}

AJEEM KHAN K - 71812201013


OUTPUT:

RESULT:

Thus the 8051 LCD interfacing programs has been executed successfully.

AJEEM KHAN K - 71812201013


EX NO : 8
ARM7 PROGRAMMING FOR LED AND LCD INTERFACE

DATE: 19.09.2024

a) Interfacing ARM7 with LED using LPC2148.

AIM:

To demonstrate the process of LED using ARM Processor.

PROCEDURE:

1. Create a new Project.


2. Select the device ARM -> ARM7.
3. Enter the source code.
4. Save it.
5. Add the source code to the target.
6. Compiled get and run the source file.
7. Generate the Hex file for the source code.
8. Add the Hex file to the LPC2000 FLASH UNITY.
9. Project the Hex file to the ARM Processor.
10. End.

PROGRAM:

#include <lpc21xx.h>

void delay(unsigned long val);

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 */

AJEEM KHAN K - 71812201013


IO1CLR = 0x00FF0000; /* Port1 16-23 Low */
delay(1000000);
}
}

void delay(unsigned long val) {


while (val > 0) {
val--;
}
}

OUTPUT:

AJEEM KHAN K - 71812201013


b) Interfacing ARM7 with LCD using LPC2148.

AIM:

To demonstrate the process of LCD using ARM7 processor.

ALGORITHM:

1. Create a new Project.


2. Select the device ARM -> ARM7.
3. Enter the source code.
4. Save it.
5. Add the source code to the target.
6. Compile, build target and run the source file.
7. Generate the Hex file for the source code.
8. Add the Hex file to the LPC2000 FLASH UNITY.
9. Project the Hex file to the ARM Processor.
10. End.

AJEEM KHAN K - 71812201013


PROGRAM:

#include <LPC21xx.h>
#include "lcd4bit.h"

void Delay(unsigned long b) {


while (--b != 0);
}
void write_command(int cmd) {
IO1CLR |= 0x00F00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1CLR |= 0x00020000; /* Register Select = 0, Command */
IO1SET |= 0x00F00000 & cmd; /* Set D4-D7 */
IO1SET |= 0x00080000; /* Enable = 1 */
Delay(30000); /* Delay ~3ms */
IO1CLR |= 0x00080000; /* Set E to low */
}
void write_data(int dat) {
IO1CLR |= 0x00F00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1SET |= 0x00020000; /* Register Select = 1, Data */
IO1SET |= 0x00F00000 & dat; /* Set D4-D7 */
IO1SET |= 0x00080000; /* Enable = 1 */
Delay(30000); /* Delay ~3ms */
IO1CLR |= 0x00080000; /* Set E to low */
}
void lcd_data(char dat) {
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd) {
write_command(cmd << 16);
write_command(cmd << 20);
}

AJEEM KHAN K - 71812201013


void printlcd(char *CPtr) {
while (*CPtr != '\0') {
lcd_data(*CPtr);
CPtr++;
Delay(20000);
}
}
void init_lcd(void) {
IO1DIR |= 0x00FE0000;
Delay(200000);

write_command(0x30 << 16);


Delay(100000);
write_command(0x30 << 16);
Delay(100000);
write_command(0x30 << 16);
Delay(100000);
write_command(0x20 << 16);

lcd_command(0x01); /* Clear display */


lcd_command(0x06); /* Auto address increment */
lcd_command(0x0C); /* Cursor off */
lcd_command(0x80); /* First location */
}
int main(void) {
init_lcd();
printlcd("eCee LPC2148 DLB");
lcd_command(0xC0);
printlcd(" rhydolabz.com ");

while (1);
}

AJEEM KHAN K - 71812201013


OUTPUT:

RESULT:

Thus the ARM7 for LED & LCD interface has been executed successfully.

AJEEM KHAN K - 71812201013


EX NO : 9
ARM7 PROGRAMMING FOR BUZZER INTERFACE

DATE: 26.09.2024

AIM:

To demonstrate the process of buzzer using ARM7 processor.

ALGORITHM:

1. Create a new Project.


2. Select the device ARM -> ARM7.
3. Enter the source code.
4. Save it.
5. Add the source code to the target.
6. compile, build target and run the source file.
7. Generate the Hex file for the source code.
8. Add the Hex file to the LPC2000 FLASH UNITY.
9. Project the Hex file to the ARM Processor.
10. End.

PROGRAM:

#include <lpc21xx.h>

void ext_interrupt(void) irq {


EXTINT = 0x02; /* Clear interrupt flag */
IO0PIN = (IO0PIN ^ 0x00010080) & 0x00010080; /* Toggle P0.7 on every interrupt */
VICVectAddr = 0x00000000; /* Acknowledge Interrupt */
}
void init_ext(void) {
PINSEL0 |= 0x20000000; /* Enable EXT1 */
EXTMODE = 0x02; /* Edge sensitive */

AJEEM KHAN K - 71812201013


EXTPOLAR = 0x02; /* On rising edge */

VICVectAddr0 = (unsigned int)ext_interrupt; /* Set Interrupt Vector in 0 */


VICVectCntl0 = 0x0000002F; /* Use it for EXT1 Interrupt */
VICIntEnable = 0x00008000; /* Enable EXT1 Interrupt */
}

int main(void) {
IO0DIR = 0x00010080; /* Set P0.7 and another pin as output */
init_ext(); /* Initialize external interrupt */
while (1); /* Infinite loop */
}

OUTPUT:

AJEEM KHAN K - 71812201013


RESULT:

Thus , the ARM7 buzzer interfacing program has been executed successfully.

AJEEM KHAN K - 71812201013


EX NO : 10
ARM7 PROGRAMMING FOR TIMER CONTROLLING
OPERATION
DATE: 10.10.2024

AIM:

To demonstrate the process of LED Blink with Timer using ARM Processor.

PROCEDURE:

1. Create a new Project.


2. Select the device ARM -> ARM7.
3. Enter the source code.
4. Save it.
5. Add the source code to the target.
6. compile ,build target and run the source file.
7. Generate the Hex file for the source code.
8. Add the Hex file to the LPC2000 FLASH UNITY.
9. Project the Hex file to the ARM Processor.
10. End.

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 */

AJEEM KHAN K - 71812201013


VICVectAddr0 = (unsigned)timer_interrupt; /* Set Interrupt Vector in 0 */
VICVectCntl0 = 0x00000024; /* Use it for Timer0 Interrupt */
VICIntEnable = 0x00000010; /* Enable Timer0 Interrupt */
T0TCR = 0x01; /* Enable Timer0 */
}

int main(void) {
init_timer();
IO1DIR = 0x00FF0000; /* Set LED channel as output */
while (1); /* Infinite loop */
}

OUTPUT:

AJEEM KHAN K - 71812201013


RESULT:

Thus the ARM7 timer controlling program has been executed successfully.

AJEEM KHAN K - 71812201013


Exp. No.: CBS
Interfacing 16X2 LCD with Arduino
Date :10/10/2024

AIM:

To interface a 16x2 LCD with an Arduino

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).

c. lcd.print("www.circuitdigest.com"): This displays


"www.circuitdigest.com" on the second line of the LCD.

d. delay(750): It adds a delay of 750 milliseconds (0.75 seconds) to


give you time to read the displayed text.

e. lcd.scrollDisplayLeft(): This function scrolls the text on the top


line of the LCD to the left.

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);

1 AJEEM KHAN K(71812201013)


// Print a message to the
LCD.lcd.print("hello,
world!");
}

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

2 AJEEM KHAN K(71812201013)

You might also like