Polling a Button
...................................................................................................................................

This chapter gives an idea of how flexible the I/O pins are, despite their simple design. The Program given below polls a button connected to one of the I/O pins (which pull the line to ground from its normal pulled-up state) and passes the state of the pin to another one and lights an LED when the button is being pressed.

Connect the following circuit in the bread board
Program to poll a button and turns on an LED

ORG 0000H                ; Execution starts here

LOOP:SETB P0.3                ; Make port P0.3 as input port
       MOV C,P0.3        ; Get the button state to carry bit
       MOV P1.6,C        ; Display button state on LED
       SJMP LOOP                ; do it continuously
       END

Program to turn on the LED when the button is pressed once and to turn off the LED when it is pressed again

       ORG 0000H                ; Execution starts here
LOOP:SETB P0.3                ; Make port P0.3 as input port
       MOV C,P0.3        ; Get the button state to carry bit
       JC LOOP                ; check if button is pressed
       CPL P1.6                ; if pressed compliment the port
       JNB P0.3,$        ; Wait until the button is released
       SJMP LOOP                ; do it continuously
       END

· Home
· 8051 Forum
· Active Topics
· 8051 Free Projects
· Blog
· Top 10
· Datasheets
· Electronic Tutorials
· Electronic Projects
· 8051 Tutorials
· 8051 Course
· 8051 Code Library
· Visual Basic for mC
· 8051 Programmer
· Assembler/IDE
· Products
· Ebooks
· Supporting Tools
· Tag Cloud
· Guest Book
· Contact Me
· Privacy policy

8051 Microcontroller Projects, free ebooks, project codes, AVR Projects, 8051 tutorials, electronic projects, ECE CSE BE final year projects, Embedded systems, AVR codes, embedded technology, LCD Interfacing tutorial,final year project ideas project downloads, engineering projects, Examples projects, 8051 Libraries, 8052, Microcontroller, Microprocessor, 8085, 8051 codes, PCB designing, Project Kits, kit