Header Ads

Header ADS

Program for Flashing LED (Delay 2 Sec.)

Introduction

Hello friends, In this post, we will learn how to write a simple program in Assembly language for flashing LED with delay of 2 seconds.
Assembly language is a low level programming language.With the invention of many high level languages, the use of assembly language has become rare these days. However, it is true that every high level language must be compiled into assembly language before it can be linked into an executable program. For the high level language programmer, understanding how the compiler generates the assembly language code can be a great benefit, both for directly writing routines in assembly language and for understanding how the high-level language routines are converted to assembly language by the compiler.

One of the first hurdles to learning assembly language programming is understanding just what
assembly language is. Unlike other programming languages, there is no one standard format that
all assemblers use. Different assemblers use different syntax for writing program statements. Many beginning assembly language programmers get caught up in trying to figure out the myriad
of different possibilities in assembly language programming.

The first step is to deciding what type of assembly language programming one want. Once you decided then it is easy to start learning. Each family of processors has its own set of instructions for handling various operations like getting input from keyboard, displaying information on screen and performing various other jobs. These set of instructions are called 'machine language instruction'.Processor understands only machine language instructions which are strings of 1s and 0s. However machine language is too obscure and complex for using in software development. So the low level assembly language is designed for a specific family of processors that represents various instructions in symbolic code and a more understandable form.

Program

;PROGRAM FOR FLASHING LED (DELAY 2 SEC.)

LEDP EQU P1                                      ;ASSIGNING P1 PORT TO LEDP
ORG 00H                                              ;STARTING OF CODE MEMORY AT 00H
SJMP MAIN                                         ;SHORT JUMP TO LABEL MAIN
ORG 30H                                              ;STARTING OF CODE MEMORY AT 30H

MAIN :
MOV A,#11111111B                            ;MOVING VALUE 01H IN ACCUMULATOR

BACK :
MOV LEDP,A                                      ;SENDING CONTENTS OF 'A' TO 'P1'
ACALL DELAY                                  ;CALLING DELAY SUBROUTINE
CPL A                                                   ;COMPLIMENT OF ACCUMULATOR
SJMP BACK                                        ;SHORT JUMP TO LABEL BACK

DELAY :
MOV R0,#28                                        ;COUNT

AGAIN:
MOV TMOD, #01H                             ;TIMER0,MODE1(16-BIT COUNTER)
MOV TL0,#00H                                   ;LOADING VALUE 00H IN TL0
MOV TH0,#00H                                   ;LOADING VALUE 00H IN TH0
SETB TR0                                            ;STARTING TIMER

HERE:
JNB TF0,HERE                                    ;CHECK FOR OVERFLOW OF TIMER0
CLR TR0                                              ;STOPPING TIMER
CLR TF0                                              ;CLEARING TF0 FOR NEXT TIMER
DJNZ R0,AGAIN                                 ;FOR COUNTING
RET                                                      ;RETURNING FROM DELAY SUBROUTINE
END                                                     ;INDICATES END OF ASSEMBLY CODE



No comments

Powered by Blogger.