Course Code and Name: Introduction to
Mechatronics Lab (ME-332L) Date:
Lab No: 04 Course Instructor: Engr. Zia Ur Rahman
Name of Student: Semester: 6th
Registration No: Department: Mechanical Engineering
Lab Task Toggling of LEDs using C Language in AT85C51 Microcontroller
1. To get familiar with Keil µ Vision IDE.
2. To learn how to upload program in STC AT89C51 Development board.
Objectives 3. To familiar with how to create a hex file.
4. To learn how to toggle LED using AT89C51.
STC AT89C51 Microcontroller
Development Board
Hardware Keil µ vision IDE
and Software Prog-ISP
Requirements Wires
LEDs
Proteus
Theory Microcontroller:
A microcontroller is a compact integrated circuit designed to govern a specific operation in
an embedded system. A typical microcontroller includes a processor, memory and input/output
(I/O) peripherals on a single chip.
Microcontroller 8051:
8051 microcontrollers are designed by Intel in 1981. It is an 8-bit microcontroller. It is built with
40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit
timers. It consists of are four parallel 8-bit ports, which are programmable as well as addressable
as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller having
crystal frequency of 12 MHz.
Toggling:
Toggle refers to the act of switching from one view, setting, or function to another. It implies
that there are only two possible options and that a user is switching between them, and usually
these options are on or off for a specific preference.
Prepared by Tanveer Uz Zaman
Diagram of Microcontroller 8051:
Fig. Development Board with AT89C51 Microcontroller
Fig. Circuit Diagram
Prepared by Tanveer Uz Zaman
Procedure First we have to write a code in C language in keil Software in which we have to
generate a delay and toggle the LEDs after that delay.
After that we have to create a hex file of that code.
On the basis of that code we have to make a connection of STC AT89C51
Microcontroller with LED as shown in the figure below.
The hex file will be uploaded into STC AT89C51 Microcontroller through Prog-
ISP.
During uploading the power of the board should be turn ON.
When code is successfully uploaded we will see that LED will toggle after some
delay.
Programming Write a code in 8051 C Language to toggle all general-purpose input output (GPIOs) pins of a port
Code
Prepared by Tanveer Uz Zaman
Results and
Conclusions
Prepared by Tanveer Uz Zaman