Embedded Lab 08-22BEC1098
Embedded Lab 08-22BEC1098
Lab Assignment: 08
Submitted By
Surya Thangaraju | 22BEC1098
Submitted To
Krithika Alias Anbu Devi m
DATE: 17.02.2025
Lab-6 Programs on I/O Ports (Hardware)
Attestation:
Aim:
To develop and implement C programs for controlling I/O ports on microcontroller hardware to
perform various LED operations, including blinking a single LED, alternating two LEDs, switching
ON one LED while others are OFF, and interfacing hardware to display specific patterns using I/O
ports.
1. Write a C program to blink an LED.
Code:
#include <reg52.h>
void Delay(void);
void main(void) {
while(1) {
LED = 0; // Turn ON LED
Delay();
LED = 1; // Turn OFF LED
Delay();
}
}
void Delay(void) {
int i, j;
for(i = 0; i < 10; i++) {
for(j = 0; j < 1275; j++) {
// Empty loop to create delay
}
}
}
Output:
2. Write a C program to blink 2 alternate LEDs.
Code:
#include <reg52.h>
void Delay(void);
void main(void) {
while(1) {
LED1 = 0; // Turn on LED 1
LED2 = 1; // Turn off LED 2
Delay();
LED1 = 1; // Turn off LED 1
LED2 = 0; // Turn on LED 2
Delay();
}
}
void Delay(void) {
int i, j;
for(i = 0; i < 10; i++) {
for(j = 0; j < 1275; j++) {
// Empty loop to create delay
}
}
}
Output:
3. Hardware implementation of Lab-6 (Exp.-3).
Code:
#include<reg51.h>
sbit mbit=P2^5;
void main(void){
mbit=1;
while(1){
if (mbit==1)
P1=0x55;
else
P1=0xAA;
}
}
Output:
Inference:
The three C programs collectively demonstrate the fundamental techniques of
controlling I/O ports on microcontroller hardware, specifically focusing on LED
operations and hardware pattern generation. These experiments serve as practical
exercises for understanding microcontroller port manipulation and hardware
interfacing.