Please update your Flash Player to view content.

                  FOLLOW  US





 
 
Timer Interrupt Based LED Blinking Program
Code Library - 8051 Assembly

Here is a simple code for Blinking a LED. The LED is connected to P2.0 & 12MHz crystal is used. The Anode of the LED is given to Vcc through a resistor & the cathode is connected to the microcontroller pin. Please check this link to see how to interface LED to Microcontroller. The LED is ON for One Second & OFF for ONE Second.

Here we will be using Timer 0 in 16 bit INTERRUPT mode to generate One second delay. We load TH0 & TL0 with a specific value & on every clock cycle TH0 & TL0 increments by 1 and when the TIMER overflows from FFFF to 0000 a Timer0 overflow flag is set & interrupt is generated.  The maximum delay that can be generated using TIMER 0 in any mode is 65535 clock cycles & since we are using 12MHz crystal the maximum delay is 65.535ms. But we require 1second delay. So we generate 50ms delay using TIMER 0 & when 20 such delays have been generated we come to know that one second has elapsed. So basically 0.05ms X 20 =1 second. So we use a RAM location “multiplier” load it with 20 and whenever the timer overflows the ram location multiplier is decremented by one. Thus when multiplier becomes zero we come to know that one second has elapsed & we toggle the LED.

 

led1 

BIT       P2.0

multiplier

EQU      30h

MULTIPLIER_DEFAULT   DATA  

20

 

ORG 0000h

ajmp main

ORG 000bh

jmp timer0_interrupt

// Jump To Interrupt Subroutine

main:

setb EA 

//Enable Interrupt

setb ET0 

//Enable timer 0 Interrupt

mov multiplier,#MULTIPLIER_DEFAULT

mov TMOD,#01h                             

// Timer 0 Mode 1(16 bit mode)

mov TH0,#3ch 

//0.05 sec           

mov TL0,#0B0H

setb TR0 

//Start Timer 0

clr led1

 

loop:

ajmp loop                                           

timer0_interrupt:

push acc

push b

push psw

push dph

push dpl

clr TF0

 clr TR0  

//Stop Timer

 mov TH0,#3ch 

//0.05 sec   

 mov TL0,#0B8H                                

//Reload Timer

djnz multiplier,c1_timer0_interrupt

mov multiplier,#MULTIPLIER_DEFAULT

cpl led1

c1_timer0_interrupt:

 setb TR0  

//Start Timer 0

pop dpl

pop dph

pop psw

pop b

pop acc

reti

end

    .
 

Add comment


Security code
Refresh

 

Featured Products

Rs600.00
Rs540.00
You Save: 10.00%

Rs1 800.00

 

Random Products



Rs3 000.00



Rs15.00



Rs60.00





Latest Video

Random Articles

  • The MOSFET
    The Metal Oxide FET - MOSFET As well as the Junction Field Effect Transistor...
  • Zener Diodes
    The Zener Diodes In the previous Signal Diode tutorial, we saw that a "reverse...
  • GSM/GPS Based Projects
    Home security system using GSM Home appliance control using GSM Child monitoring using GSM +...
  • The PN Junction
    The PN junction In the previous tutorial we saw how to make an N-type...

Search Products

User Login






 
 
.
 TUTORIALS
.
  8051 Tutorial
 
  Power Supply
 
CODE LIBRARY
.

  8051 Assembly
 
  C Code Library

.
 PROJECTS
.
  Project List
 
  Synopsis and Abstract
 
DOWNLOADS
.

  Datasheets
 
  Download

.
 POPULAR
.
  About Us
 
  DNA Shop
 
  Totorial
 
  Code Library
 
  Download
 

.
 CONTACT US
.

Mr. Amol Shah

DNA Technology Nashik,

Maharashtra 422009 India

Phone : 0253-3023939

Mobile : 09225145135

Email : contact@dnatechindia.com