Attention !!! We are shipping orders now but due to Covid-19 situation it can take 1-2 days for your orders to be shipped from our Nashik warehouse. If you have any queries feel free to contact us. Thank you for your support and understanding.
  • 8412906903

Product categories

Have You Seen

Samsung 18650 2600mah Li-ion Battery

Samsung 18650 2600mah Li-ion Battery

Samsung ICR18650-26J 2.6Ah BatteryOriginal Samsung 18650 2600 mah Lithium-ion BatteryThis is or..

Rs.247.80 (inc GST)
Rs.210.00 + GST

SKU: 1183 | DAB424
Stock: 0
Arduino Mega 2560 Pro Mini

Arduino Mega 2560 Pro Mini

Mega Pro 2560 Development Board Mega 2560 Pro a  Atmega2560 based compact Arduino MegaThis..

Rs.889.72 (inc GST)
Rs.754.00 + GST

SKU: 2058 | DAB079
Stock: 25

Switch Debouncing Program

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.



bit P2.0


bit P2.1


bit P1.0

ORG 0000h

setb switch1

//initialize switch 1 as input

setb led1

//Turn OFF LED1

setb led2

//Turn OFF LED2


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



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

cpl led2

ajmp wait



//Subroutine for generating 20ms delay

mov r7,#245


mov r6,#40

djnz r6,$

djnz r7,l1_debounce_delay



Written by Administrator