You are on page 1of 14

Course Code: 19ECE304 Name: N P Ganesh Kumar

Course Title: Microcontrollers and Roll No: CH.EN.U4ECE21016


cascasc Interfacing
Semester: 5th
Course Faculty: Dr. C Ganesh Kumar
Academic Year: 2023-2024

Lab Report – 2

Software Used

&

General Instruction

1. MOV: Moves 16-bit data to the register.


2. AREA: Assigns and instructs the assembler to assemble the code.
3. END: To denote the completion of the program.
4. CODE: To specify whether it is code or data sec􀆟on.
5. READONLY: To make it viewable but not editable.
List Of Experiment

1. LED flash program


2. LED group swap program
3. LED increment program
4. LED decrement program
5. Switch – Blink program
6. Four LED alternate blink program
7. Eight LED alternate switch program

LED Flash

Source Code

#include <lpc21xx.h>
// #include <stdio.h> not required but add it for sanity check
void delay(){
int i;
for(i=0; i<0xfffff; i++);
}
int main(){
PINSEL1 = 0x00000000;
IO1DIR = 0x00FF0000;
while(1){
IO1SET = 0X00FF0000;
delay();
IO1CLR = 0X00FF0000;
delay();
}
}

Output
Inference

In the above code, we set the pins from 16 – 23 in port 1 as output. We use the bits to access
each led. Here F in hex indicates 1111 in binary. We create a rough delay function using for
loop. Using the while loop, we create an infinite looping sequence where we SET and CLR the
assigned pins with a delay.

LED Position Swap

Source Code

#include <lpc21xx.h>
void delay(){
int i;
for(i=0; i<0xefff; i++);
}
int main(){
PINSEL1 = 0X00000000;
IO1DIR = 0XFFFFFFFF;
while(1){
IO1SET = 0X00F00000;
delay();
IO1CLR = 0x00f00000;
delay();
IO1SET = 0x000f0000;
delay();
IO1CLR = 0x000f0000;
delay();
}
}
Output

Inference

We begin with basis from previous code, and instead of using 2x4 LEDs for blinking we
split it to two 4 LED pairs. Therefore, we select 16-19 LEDs with F and those will be
turned on for the first cycle, and for the next cycle, 21-24 LEDs will be selected. For each
of these steps we add a delay to make it perceivable to human eye due to phenomenon of
persistent vision in our retina.

LED Increment Sequence

Source Code

#include <lpc21xx.h>
void delay(){
int i;
for(i=0; i<0xfffff; i++);
}
int main(){
PINSEL1 = 0X00000000;
IO1DIR = 0XFFFFFFFF;
while(1){
IO1SET = 0X00FF0000;
for(int i=15; i<24; i++){
IO1CLR = 0X00000001<<i;
delay();
// IO1SET = 0X00000001<<i;
// delay();
// Change the order of clear and set to make it all on and blink
shift to blink shit all off
}
}
}
Output
Inference

Using the LSL that is being looped and incremented using the for loop, we are able to create an
increasing sequence of LED lighting. In the above output pictures, we can observe that the
output LEDs are shifting from 16 to 23.

Note: For some reason in software, the marked palaces are off, and the clear ones are on in
IO_SET. Also, the code is modified from the original to make it look good on the LPC kit.

LED Decrement Sequence

Source Code

#include <lpc21xx.h>
void delay(){
int i;
for(i=0; i<0xfffff; i++);
}
int main(){
PINSEL1 = 0X00000000;
IO1DIR = 0XFFFFFFFF;
while(1){
IO1CLR = 0X00FF0000;
for(int i=23; i>=16; i--){
IO1SET = 0X00000001<<i;
delay();
// IO1SET = 0X00000001<<i;
// delay();
}
}
}
Output

Inference

Similar to the previous code, we use for loop and LSL to control the sequence. The only
difference is in the for loop. Instead of increment, we decrement, that makes it a decrementing
LED sequence.
Blink of Switch

Source Code

#include <lpc21xx.h>
int main(){
IO1DIR = 0X00ff0000; // For the last LED
OUTPUT
IO0DIR = 0X0; // For button all as input
while(1){
for(int i=16; i<24; i++){
if((IO0PIN & (0X00000001<<i)) == 0){
IO1CLR = 0X00000001<<i;
}
else{
IO1SET = 0X00000001<<i;
}
}
}
}

Output
LED in OFF condition if switch is not pressed

LED in ON condition if switch is pressed

Inference

In this above code, we scan through each button to check if there’s any button is pressed and
high turns to low. If the condition is met, the led corresponding to that button is turned on.
We can understand that from the above interactive output emulator screenshots.
Four LED Alternative Blink

Source Code

#include <lpc21xx.h>
void delay(){
int i;
for (i=0; i<=0xfffff; i++);
}
int main() {
int i;
while(1){
IO1SET = 0X00030000;
delay();
IO1CLR = 0X00030000;
delay();
IO1SET = 0X000C0000;
delay();
IO1CLR = 0X000C0000;
delay();
}
]

Output
Inference

In the above code, we can see that the LEDs 1 and 2 blink first, followed by LEDs 3 and 4.
This happens in a sequence where we label LED 1 as 16 and LED 2 as 17 and so on. Since in
the question it is mentioned as port 1 to be used, we have used port 1’s pins for configuring
the LEDs.

Eight LED Alternative Switch

Source Code

#include<lpc21xx.h>
int main() {
IO1DIR = 0x00FF0000;
IO0DIR = 0x00;
while(1) {
if((IO0PIN & (0x00010000))==0){
IO1CLR= 0x00550000;
}
else{
IO1SET= 0x000550000;
}
if((IO0PIN & (0X00020000)) == 0){
IO1CLR = 0X00AA0000;
}
else{
IO1SET = 0X00AA0000;
}
}
}
Output

Inference

The above code integrates the button press and multiple LEDs integration together. While
pressing the B1, in port 0 and pin 16, LEDs in the odd place turns on. Similarly, while
pressing the B2 at the port 0 and pin 17, the LEDs at the even place turns on.
Cessation Of this Lab

From this lab , by performing the above experiments I came to know about various registers such
as IOxDIR, IOxSET, IOxCLR, IOxPIN which are used for flash , swap , rotate programs. And
by converting the code into hex file so that we can dump our code for LED experiments into
flash magic software for hardware simulation and see how the LED blinks for the various
condition. At first, we did basic LED blinking and switching after that we performed alternate
blinking using switches and a greater number of LEDs. At last, we worked on blinking 4 LEDs
(1st and 2nd LED should blink one time, 3rd and 4th LED should blink another time) and then
on 8 LEDs with switch to control the blinking of LEDs (Switch 1 in PO.12 - 1st,3rd,5th and 7th
LED should blink and Switch 2 in PO.17 - 2nd,4th,6th and 8th should blink)

You might also like