logo

Loading...
  • Home
  • Categories
  • Manufacturers
  • Products
  • PROJECTS
  • TUTORIAL
  • CODE LIBRARY
  • Blogs
  • Contact us
  1. Home
  2. Blogs
  3. Timer Based Led Blinking Program

Timer Based Led Blinking Program

17 July 2011
2 min read
23960 views

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 mode to generate One second delay. The maximum delay that can be generated using TIMER 0 in any mode is 65535 clock cycles & since we are using 12MHz crystal 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 //RAM Location

MULTIPLIER_DEFAULT DATA 20 //20 x 0.05 = 1 sec

ORG 0000h

mov multiplier,#MULTIPLIER_DEFAULT

mov TMOD,#01h // Timer 0 Mode 1(16 bit mode)

mov TH0,#3ch //0.05 sec

mov TL0,#0B8H

setb TR0 //Start Timer 0

loop:

clr led1 //TURN ON LED

call check_timer //wait for 1 second

setb led1 //TURN OFF LED

call check_timer //wait for 1 second

ajmp loop

check_timer:

jnb TF0,$ //wait for timer to over flow

clr TF0 //clear TIMER 0 flag

clr TR0 //Stop Timer 0

mov TH0,#3ch //0.05 sec, Reload timer 0

mov TL0,#0B8H

setb TR0 //Start Timer 0

djnz multiplier,check_timer //Decrement multiplier by 1 & check if its 0

mov multiplier,#MULTIPLIER_DEFAULT

ret

end

Back
newsletter image

Join our mailing list

Get bits and bytes of noise free Information

*No Noise(spam) only Information

Get In Touch

Office

DNA Solutions, Flat no 1, Raja Jeet Recidency, p no 61 Sr no 102, Wadala Shivar Indira nagar, Nashik, 422009, Maharashtra, India

Shop

FH11-12, Thakker Bazar NEW CBS, Nashik, 422002, Maharashtra, India

Got Questions? Call us at

Neha (Rest of India): 7972667515, 8412906903

Prachi (Nashik): 8669102120

site@example.com

Information

  • FAQs
  • About Us
  • Shipping & Delivery
  • Returns & Cancellation
  • Privacy Policy
  • Payment Information
  • Terms & Conditions
  • Contact us
  • Products
  • Blogs
Cities Cover

Shivaji Nagar | Namrup | Thane | Pilani | Ballia | Darbhanga | Kannur | Junagadh | Jaisalmer | Jamshedpur | Itanagar | Amravati | Navi Mumbai | Durgapur | Dahod | Pimpri | Madurai | Agra | Mangalore | Kalyan | Port Blair | Davangere | Kochi | Pondicherry | Mathura | Kalyan | Raigad | Thane | Nagpur | Bhubaneswar

COPYRIGHT © 2026 DNA Solutions, INDIA . ALL RIGHTS RESERVED.

footer-logos