By Abdul Rehman
Blink and LED is one of the simplest task which we are going to solve in this tutorial. This could be difficult if we try to do this in assembly language. We are going to write LED Blink 8051 Assembly language code in this tutorial. Before we get started let’s review what kind of previous understanding we need to start writing this code.
Before jumping into the code we must understand the basic registers and internal architecture of the 8051 microcontroller. Also basic understanding of simulation is required because we are going to test this code in proteus. So if you have not watch my basic assembly language and lecture before you must check out my previous YouTube video about assembly language Introduction.
Now that you may know basic assembly introduction, let’s start understanding the development logic for LED blinking code. So the main steps to make one LED blink we need to follow these orders
So these are the basic steps which you need to follow.
Well, you may already aware of the word delay which means to lag some event by some time. But the question arises what is the Delay in Assembly language? Specially in Embedded systems?
To answer the above question we must understand that the Microcontroller runs very very fast. Just like, in case of 8051, connected with 12MHz crystal, the one instruction is executed in one micro seconds.
So if in normal case of blinking, where we only need to turn on led and then turn off LED and repeat. Microcontroller will do this so rapidly that we won’t be able to see the actual blinking. We (humans) cannot visualize the on and off of LED at 1us. So for making this visualize able we need to slow down microcontroller.
But the microcontroller always following some instructions. That’s why to slow down the microcontroller we also have to write some code to let microcontroller do some task all the time. We create a Delay task for this purpose and call this a Delay subroutine in assembly language.
To write the Delay function in 8051 assembly language we fill some 8bit register with a fix number and then ask 8051 microcontroller to decrement that register with DJNZ Instruction. Once it’s done we repeat the task until we wasted enough microseconds of the 8051 microcontroller. Here is the one register delay function which is called the Delay subroutine in Assembly Language
DELAY1: MOV R7,#255
DJNZ R7,$
RET
Code language: PHP (php)
Even though we took 255 decrements for the R7 register but still this is not enough for human’s to visualize the blinking. So we need at-least 3 registers delay to accomplish LED blinking task. So here is the final complete code for the LED blink in 8051 assembly language.
LED BIT P1.0
;--------------------------------------------
ORG 00H
;--------------------------------------------
MAIN:
CLR LED
ACALL DELAY3
SETB LED
ACALL DELAY3
SJMP MAIN
;-------------------------------------------
DELAY3:
MOV R7,#5
D3L1: MOV R6,#255
D3L2: MOV R5,#255
DJNZ R5,$
DJNZ R6,D3L2
DJNZ R7,D3L1
RET
;-----------------------------------------------
END
;-------------------------------------------------
Code language: PHP (php)
Here is the YouTube video I created for this tutorial if you like to see things in action
19 April 2023
07 April 2023
07 April 2023
FYP Solutions Powered By Impressive Business WordPress Theme