CYCLE I
Experiments using 8051.
Expt. No: Programming Arithmetic and Logical Operations in Date:
8051.
Aim:
To understand and implement basic arithmetic and logical operations in the 8051
microcontroller using assembly language programming.
Components Required:
1. Keil Software
2. 8051 Microcontroller
3. PC
Assembly Language Program:
; Program: Basic Arithmetic and Logical Operations in 8051
; Microcontroller: AT89C51
; Assembler: Keil or any 8051 assembler
ORG 0000H ; Start of program
; ------------------------------
; Initialize values
MOV A, #25H ; Load 25H into accumulator A
MOV R0, #12H ; Load 12H into register R0
; ------------------------------
; ----- ADDITION -----
ADD A, R0 ; A = A + R0 (25H + 12H = 37H)
MOV R1, A ; Store result in R1
; Reset A for next operation
MOV A, #25H
; ----- SUBTRACTION -----
CLR C ; Clear carry before subtraction
SUBB A, R0 ; A = A - R0 (25H - 12H = 13H)
MOV R2, A ; Store result in R2
; ----- MULTIPLICATION -----
MOV A, #06H ;A=6
MOV B, #03H ;B=3
MUL AB ; A = A * B = 18H (It displays only hexadecimal value: 18 Decimal = 12 H)
MOV R3, A ; Store result in R3
; ----- DIVISION -----
MOV A, #10H ; A = 16
MOV B, #04H ;B=4
DIV AB ; A = A / B = 4, B = A % B = 0
MOV R4, A ; Store quotient in R4
MOV R5, B ; Store remainder in R5
; ----- LOGICAL AND -----
MOV A, #0F0H
ANL A, #0AAH ; A = A AND 0AAH = 0A0H
MOV R6, A
; ----- LOGICAL OR -----
MOV A, #0F0H
ORL A, #0AAH ; A = A OR 0AAH = 0FAH
MOV R7, A
; ----- LOGICAL XOR -----
MOV A, #0F0H
XRL A, #0AAH ; A = A XOR 0AAH = 05AH
MOV 30H, A ; Store result in internal RAM location 30H
; ----- INCREMENT / DECREMENT -----
MOV A, #09H
INC A ; A = A + 1 = 0AH
DEC A ; A = A - 1 = 09H
MOV 31H, A ; Store result in 31H
SJMP $ ; Infinite loop to end the program
END ; End of program
Output:
Addition
Subtraction
Multiplication
Division
AND Operation
OR Operation
XOR Operation
Increment Operation
Decrement Operation
Result:
The 8051 assembly language program for performing arithmetic and logical
operations was successfully written, compiled, and simulated using the Keil µVision IDE
and implemented using 8051 Microcontroller.
Expt. No: Date:
Generation of Square waveform using 8051.
Aim:
To write and simulate an Assembly language program using the 8051
microcontroller to generate a continuous square waveform on a specified port pin (e.g.,
P2.1) and observe the output using the Logic Analyzer.
Components Required:
1. Keil Software
2. 8051 Microcontroller
3. PC
Assembly Language Program:
ORG 0000H ; Start of program memory
MOV TMOD,#10H
NXT: MOV TL1,#8FH
MOV TH1,#0D8H
SETB TR1
WAIT: JNB TF1,WAIT
CLR TR1
CPL P2.1
CLR TF1
SJMP NXT
Settings:
1. After building the program, go to Debug and click “Start/Stop Debug Session.”
2. Click “Run.”
3. During simulation, open the Logic Analyzer panel and click “Setup.”
4. In the Current Logic Analyzer Signals section, enter P2.1.
5. Set the Signal Type to Bit, select “Hexadecimal Display,” and close the setup
window.
6. A proper square waveform will be displayed in the Logic Analyzer.
Output:
Result:
Thus, the continuous square waveform will be generated on port pin P2.1 of the
8051 microcontroller and the waveform can be visualized using the Logic Analyzer with a
toggling pattern between logic high and logic low at fixed intervals.
Experiments using ARM/Raspberry Pi/ ESP32.
Expt. No: Date:
Blinking of two LEDs in a toggle WAY
Aim:
To write and execute an C program using ARM microcontroller to blink two LEDs in
a toggle manner such that when one LED is ON, the other is OFF, and they alternate their
states continuously with a delay.
Components Required:
1. Keil Software
2. ARM Board
3. Flash Magic
4. PC
C Program:
#include <LPC214x.H> /* LPC214x definitions */
void wait (void) /* wait function */
{
int d;
for (d = 0; d < 1000000; d++); /* only to delay for LED flashes */
}
int main (void)
{
IODIR0 = 0x80002000; /* P0.13 and P0.31 defined as Outputs */
while (1) /* Loop forever */
{
IOCLR0 = 0x80002000; /*Active Low outputs makes the
LEDs ON*/
wait ();
IOSET0 = 0x80002000; /* High outputs makes the LEDs
OFF*/
wait ();
}
}
Settings:
1. After building the program, locate the .hex file generated in the project directory.
2. Ensure that all necessary settings are correctly configured, such as the Device Name,
Clock Frequency, and other project-specific parameters. Refer to the screenshot
below for guidance.
3. Once the build process is complete, the hex file will be automatically generated.
4. This hex file is required to load the program onto the ARM development board.
5. To load the program onto the board, open Flash Magic software.
6. In the Flash Magic interface, browse and select the generated hex file. Then, press and
hold the push button on the kit and press the reset button.
7. Now click Start in Flash Magic. Once the program is successfully loaded, release the
push button and press the reset button again. The LEDs on the kit will start blinking,
indicating successful program execution.
Output:
Result:
The C program was successfully executed on the ARM development board. The two LEDs
connected to the specified GPIO pins blinked in a toggle pattern — when one LED was ON,
the other was OFF — confirming the correct implementation of GPIO (General Purpose
Input/Output) pin toggling using ARM.
Expt. No: Date:
Interfacing Stepper Motor with ARM Microcontroller.
Aim:
To interface a stepper motor with the ARM microcontroller and develop a program to
control its rotation in clockwise and counter-clockwise directions.
Components Required:
1. Keil Software
2. ARM Board
3. Stepper Motor
4. Flash Magic
5. PC
C Program:
/************************************************************************************/
/* FILE : main_LCD_Test.c */
/* AUTHOR : Rajasekaran.K, SM Micrro System, Tamabaram, Chennai */
/* DESCRIPTION: This file is part of example projects given with SM Micrro system's */
/* ARM LPC2148 development Board. The example projects should be used only for */
/* educational purpose and not for product development */
/************************************************************************************/
/* This is a test program to display strings in LCD module in the ARM LPC2148 */
/* development board itself */
/************************************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
#define step1 0x00010000 /* P1.16 */
#define step2 0x00020000 /* P1.17 */
void wait (void)
{ /* wait function */
int d;
for (d = 0; d < 10000; d++); /* only to delay for LED flashes */
}
void call_stepper_forw()
{
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00040000;
wait();
wait();
// wait();
//wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00060000;
wait();
wait();
// wait();
// wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00070000;
wait();
wait();
// wait();
// wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00050000;
wait();
wait();
// wait();
// wait();
}
/*void call_reverse(void)
{
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00050000;
wait();
wait();
// wait();
//wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00070000;
wait();
// wait();
//wait();
//wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00060000;
wait();
// wait();
//wait();
//wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00040000;
wait();
// wait();
//wait();
//wait();
} */
int main (void)
{
IODIR1 |= 0xFFFFFFFF;
IOCLR1 |= 0X00FF0000;
wait();
while(1) /*Loop Forever*/
{
call_stepper_forw();
//call_reverse();
wait();
// wait();
// wait();
// wait();
IOCLR1 = 0X00FF0000;
}
}
Settings:
1. After building the program, locate the .hex file generated in the project directory.
2. Ensure that all necessary settings are correctly configured, such as the Device Name,
Clock Frequency, and other project-specific parameters. Refer to the screenshot
below for guidance.
3. Once the build process is complete, the hex file will be automatically generated.
4. This hex file is required to load the program onto the ARM development board.
5. To load the program onto the board, open Flash Magic software.
6. In the Flash Magic interface, browse and select the generated hex file. Then, press and
hold the push button on the kit and press the reset button.
7. Now click Start in Flash Magic. Once the program is successfully loaded, release the
push button and press the reset button again. The LEDs on the kit will start blinking,
indicating successful program execution.
Output:
Result:
The stepper motor was successfully interfaced with the ARM microcontroller. A program
was developed to rotate the motor in both clockwise and counter-clockwise directions with
defined steps.
Expt. No: Date:
Interfacing Keyboard with ARM Microcontroller.
Aim:
To interface a 4x4 matrix keypad with the ARM microcontroller and develop a program to
detect and display the key pressed using C program.
Components Required:
1. Keil Software
2. ARM Board
3. Flash Magic
4. PC
C Program:
Main Program:
/******************************************************************************/
/* Description: This program gets input from Matrix key board and displays corresponding
*/
/* Key value in 7segment display. Hence this prohram demonstrates both */
/* 7 segment display as well as Matrix key board. */
/* P1.16 to P1.23 are inputs from matrix key board, */
/* P1.24 to P1.31 are outputs to 7 segment display */
/*****************************************************************************************
/
/* ------- matrix key board description---------- */
/* -- -- -- -- */
/* row1 --| c |-- --| d |-- --| e |-- --| F |-- (SW1,SW2,SW3,SW4) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row2 --| 8 |-- --| 9 |-- --| A |-- --| b |-- (SW5,SW6,SW7,SW8) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row3 --| 4 |-- --| 5 |-- --| 6 |-- --| 7 |-- (SW9,SW10,SW11,SW12) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row4 --| 0 |-- --| 1 |-- --| 2 |-- --| 3 |-- (SW13,SW14,SW15,SW16) */
/* -- -- -- -- */
/******************************************************************************/
#include <LPC214x.h>
#include "mat_7seg.h"
#include "lcd.h"
int main()
{
unsigned int key, last_key, Disp_key;
init_Matrix_7seg(); // Initialize matrix keyboard and 7segment dispaly
clearall_7seg(); // clear 7 segment display
last_key = 0; // Initialize this variable to zero
while(1)
{
key = catch_key(); // scan for a valid key press
if(key != 0) // zero means no key is pressed
{
if(key != last_key) // check whether the same key is pressed again(assume this as
STEP1)
{
Disp_key = key; // valid new key is stored in another variable
last_key = key; // this variable's value is used for STEP1
}
}
//Display_Number(Disp_key); /*this function is used to display number in
decimal format*/
Alpha_Dispay(4,Disp_key); /*this function is used to display number in hex
format (single digit only)*/
}
}