logo

Loading...
  • Home
  • Categories
  • Manufacturers
  • Products
  • PROJECTS
  • TUTORIAL
  • CODE LIBRARY
  • Blogs
  • Contact us
  1. Home
  2. Blogs
  3. Switch Debouncing Program

Switch Debouncing Program

17 July 2011
2 min read
20746 views

Switch Interfacing & Debouncing

Over here we consider ONE Switch & TWO LED connected to a microcontroller. Please check the SWITCH INTERFACING and the LED INTERFACING article to see how to connect Switches & LED’s to a microcontroller.

Here is a program that will TURN ON A LED1 if a switch is debounced properly & will TOGGLE LED2 if there is some error in switch debouncing. LED1 will be ON until the switch is pressed & will turn OFF as soon as it’s released. We have taken the debounce period as 20ms. So once a LOW signal has been received from the switch the controller will again check the switch status after 20ms & if at that time the switch is high LED2 will be toggled and if the switch is LOW LED1 will be turned ON.

led1

bit P2.0

led2

bit P2.1

switch1

bit P1.0

ORG 0000h

setb switch1

//initialize switch 1 as input

setb led1

//Turn OFF LED1

setb led2

//Turn OFF LED2

wait:

jb switch1,wait

// Wait till switch1 has been pressed

call debounce_delay

jb switch1,c1_wait

//After debouncing period, switch is low hence switch succesfully debounced

clr led1

//Turn ON LED1

jnb switch1,$

//wait till switch has been released

setb led1

//Turn OFF LED1

ajmp wait

c1_wait:

//Switch PIN high after debounce period so error in debouncing

cpl led2

ajmp wait

debounce_delay:

//Subroutine for generating 20ms delay

mov r7,#245

l1_debounce_delay:

mov r6,#40

djnz r6,$

djnz r7,l1_debounce_delay

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

*Note : We provide GST Tax Bill for claiming Tax Input Credit. GST bill will be provided in the name of DNA Solutions (GST No: 27BGPPS9522M1ZF) or DNA Solutions Private Limited (GST No: 27AAFCE7605R1Z).

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

footer-logos