Push Button Interfacing with 8051 microcontrollers

///Push Button Interfacing with 8051 microcontrollers

Push Button Interfacing with 8051 microcontrollers

A microcontroller, being an integrated circuit with a processor, contains support devices like program memory, data memory, I/O ports and serial communication interface integrated together. Since all the required support devices are available with the microcontroller, external interfacing of devices is not required. One of the most popular microcontrollers is Intel 8051. It belongs to the MCS-51 family of Intel microcontrollers. Many companies later adopted the MCS-51 core to develop their own microcontrollers and all these devices could be operated with the MCS-51 instruction sets. The basic difference between these devices is in the size of the memory or in the presence of an ADC or DAC. AT89S51 is such a microcontroller developed by Atmel. This chapter talks about how push-button interfacing with AT89S51 is carried out.

Push Buttons

Push buttons are used for switch mechanisms in embedded systems. A switch connected to an IO pin when pressed can change the state of the pin to low or high depending on its initial state. The change can be identified in firmware and can make the controller work accordingly. This tutorial includes a simple example of interfacing a push button with the AT89S51 controller so as to glow an LED.

Push button interfacing with AT89S51

The push button is connected to P0.0 (0th pin of port0). The pin is connected externally with a pull-up resistor since there is no internal pull-up resistor for port 0. The other end of the pushbutton is connected to ground. The voltage at the pin will be VCC when the button is not pushed. It will get grounded on pressing the button. The LED connected to the P2.0 pin is connected with a series resistor to limit the current.

Firmware Interfacing

The initial part of the code includes the library files and defines the identifiers.

The reg51.h is general header file for 8051 microcontrollers which define all the identifiers. P2.0 pin with LED connected is the macro defined as LED and the pin P0.0 with push button is a macro defined as switch_pin.

A delay function is defined before the main to keep a small delay for blinking the LED.
The whole process of scanning for the input at port 0 and configure for the blinking of LED is done inside the main function.

The port pin with push button connected should be configured as input pin by loading a 1 in the corresponding port bit. The LED is made off initially by loading a 1 in the P2.0. Inside an infinite loop, the pin with push button connected is scanned continuously for a low input. If we press the button the input pin will get grounded and voltage will be zero. LED blinks as long as the button is pressed.

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
Spread the love, share this

Leave A Comment

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
close-link
25% OFF - OpenLabPro Course
Use Coupon: CRS25UL

 
8051 Microcontroller Primer
Want to learn indepth programming, peripheral interfacing and driver development?
close-link
Launched: IoT online Course - 25% Off when you complete your order today.
Checkout Now
close-image

Subscribe To our Email Newsletter

Be the first to get latest updates and exclusive content straight to your email inbox.
Send me Tutorials and Guides
close-link