KEMBAR78
8051 Lab Manual EmbeddedC | PDF | Central Processing Unit | Integrated Circuit
0% found this document useful (0 votes)
54 views2 pages

8051 Lab Manual EmbeddedC

The document is a lab manual for the 8051 microcontroller using Embedded C, focusing on basic and advanced tasks. It includes various tasks such as LED blinking, number addition, toggling bits, and implementing serial communication. Each task is accompanied by sample code demonstrating the functionality on the AT89C51/52 microcontroller using the EdSim51 simulator.

Uploaded by

G RAJESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

8051 Lab Manual EmbeddedC

The document is a lab manual for the 8051 microcontroller using Embedded C, focusing on basic and advanced tasks. It includes various tasks such as LED blinking, number addition, toggling bits, and implementing serial communication. Each task is accompanied by sample code demonstrating the functionality on the AT89C51/52 microcontroller using the EdSim51 simulator.

Uploaded by

G RAJESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8051 Microcontroller Lab Manual Using Embedded C

Platform: EdSim51 Simulator


Language: Embedded C
Microcontroller: AT89C51/52

PART 1: Basic & Intermediate Tasks

Task 1: LED Blinking on P1.0


#include <reg51.h>
void delay() { int i, j; for(i = 0; i < 1000; i++) for(j = 0; j < 100; j++); }
void main() { while(1) { P1 = 0x01; delay(); P1 = 0x00; delay(); } }

Task 2: Add Numbers from Port 1 and Port 2, Output to Port 3


#include <reg51.h>
void main() { unsigned char a, b, c; P1 = 0xFF; P2 = 0xFF; a = P1; b = P2; c = a + b; P3 = c; }

Task 3: Toggle All Bits on Port 1


#include <reg51.h>
void delay() { int i, j; for(i = 0; i < 1000; i++) for(j = 0; j < 100; j++); }
void main() { while(1) { P1 = 0xFF; delay(); P1 = 0x00; delay(); } }

Task 4: Switch on P2.0 Controls LED on P1.0


#include <reg51.h>
void main() { while(1) { if(P2 & 0x01) P1 = 0x01; else P1 = 0x00; } }

Task 5: 7-Segment Display Counter (0-9) on Port 2


#include <reg51.h>
void delay() { int i, j; for(i = 0; i < 1000; i++) for(j = 0; j < 1275; j++); }
unsigned char seg_code[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void main() { int i; while(1) { for(i = 0; i < 10; i++) { P2 = seg_code[i]; delay(); } } }

Task 6: LED Blink Using Timer0 Delay


#include <reg51.h>
void delay_1s() { TMOD = 0x01; TH0 = 0xFC; TL0 = 0x66; TR0 = 1; while(TF0 == 0); TR0 = 0; TF0 = 0;
}
void main() { while(1) { P1 = ~P1; delay_1s(); } }

Task 7: Square Wave on P1.1 Using Timer


#include <reg51.h>
void delay_timer() { TMOD = 0x01; TH0 = 0xFF; TL0 = 0x9C; TR0 = 1; while(!TF0); TR0 = 0; TF0 = 0;
}
void main() { while(1) { P1 ^= 0x02; delay_timer(); } }

Task 8: LED Bit Scrolling (P1.0 to P1.7)


#include <reg51.h>
void delay() { int i, j; for(i = 0; i < 1000; i++) for(j = 0; j < 100; j++); }
void main() { unsigned char val = 0x01; while(1) { P1 = val; delay(); val <<= 1; if(val == 0) val
= 0x01; } }

PART 2: Advanced Tasks

Task 9: External Interrupt to Toggle LED


#include <reg51.h>
sbit led = P2^0;
void external0_ISR(void) interrupt 0 { led = ~led; }
void main() { IE = 0x81; while(1); }

Task 10: Serial Communication: Echo Character


#include <reg51.h>
void Serial_Init() { TMOD = 0x20; TH1 = 0xFD; SCON = 0x50; TR1 = 1; }
void main() { char ch; Serial_Init(); while(1) { while(RI == 0); ch = SBUF; RI = 0; SBUF = ch;
while(TI == 0); TI = 0; } }

Task 11: Software PWM to Control LED Brightness


#include <reg51.h>
sbit led = P1^0;
void delay(unsigned int time) { unsigned int i, j; for(i = 0; i < time; i++) for(j = 0; j < 100;
j++); }
void main() { while(1) { led = 1; delay(5); led = 0; delay(15); } }

Task 12: Simulated ADC Interface (Conceptual)


#include <reg51.h>
void main() { unsigned char analog_input; P1 = 0xFF; while(1) { analog_input = P1; P2 =
analog_input; } }

You might also like