SlideShare a Scribd company logo
5
Most read
10
Most read
17
Most read
Switches and LEDs Interface to the 8051
Microcontroller
Prepared by:
Afrah Salman
Switch Basics
• A switch is an electrical component that can break an electrical
circuit, interrupting the current or diverting it from one
conductor to another.
• If we directly connect a switch to one of the microcontroller port
pins, the pin floats when the switch is open. Meaning, it is not at
a fixed logic level 0v or 5v.
Switches and LEDs interface to the 8051 microcontroller
PinAssignment with 8051
Interfacing Switch
• Fig. 1 shows how to interface the switch to microcontroller. A simple
switch has an open state and closed state. However, a
microcontroller needs to see a definite high or low voltage level at a
digital input. A switch requires a pull-up or pull-down resistor to
produce a definite high or low voltage when it is open or closed. A
resistor placed between a digital input and the supply voltage is
called a "pull-up" resistor because it normally pulls the pin's voltage
up to the supply.
Fig.1InterfacingswitchtoMicrocontroller
LED Basics
• Light Emitting Diodes are the semi conductor light sources.
Commonly used LEDs will have a cut-off voltage of 1.7V and
current of 10mA. When an LED is applied with its required
voltage and current it glows with full intensity. The Light
Emitting Diode is similar to the normal PN diode but it emits
energy in the form of light. The color of light depends on the
band gap of the semiconductor.
Switches and LEDs interface to the 8051 microcontroller
Interface to the Microcontroller
• Now we could go ahead and interface it to the
microcontroller, but we would rather interface 8 switches
and 8 LED's to two ports as shown in the schematic below.
Switches and LEDs interface to the 8051 microcontroller
• As we can see the schematic has basic circuits for
oscillator, reset and power connections for the
microcontroller.
• A DIP (dual in line package) Switch, array of 8
switches is connected to PORT3 AND 8 LEDs
toPORT2.
• Observe the RR1 component, it is array of 8 resistors
in a single pack(SIP). It is as good as connecting 8
pull-up resistors as shown in figure 1. You could also
use 8 discrete resistors as well.
Interfacing Switch with 8051
• We now want to control the LED by using switches in 8051 Slicker
Board. It works by turning ON a LED & then turning it OFF when
switch is going to LOW or HIGH. The 8051 Slicker board has eight
numbers of point LEDs, connected with I/O Port lines (P0.0 – P0.7)
to make port pins high. Eight switches, connected with I/O port
lines (P2.0 – P2.7) are used to control eight LEDs.
Circuit Diagram to Interface Switch with 8051
Example1:The following program will make the value of PIN3.1 keeps
toggling (ON/OFF) after some delay.
org 00H
;MAIN PROGRAM
Toggle: MOV P3, #01H ;move 00000001 to PORT3
CALL delay ;execute delay
MOV A, P3 ;move PORT3 value to
accumulator
CPL A ;complement PORT3 value
MOV P3, A ;move 11111110 to PORT3
CALL delay ;execute delay
SJMP Toggle
;DELAY SUB-ROUTINE
delay: MOV R5, #10 ;load register R5 with 10
third: MOV R6, #200 ;load register R6 with 200
second: MOV R7, #200 ;load register R7 with 200
DJNZ R7, $ ;decrement R7 till it is zero
DJNZ R6, second ;decrement R6 till it is zero
DJNZ R5, third ;decrement R5 till it is zero
ret ;go back to main program
END
Example2:Aswitch is connected to pin PI .7. Write a program to check the
status of SW and perform the following:
If SW=0, send letter ‘N’ to P2., If SW=1, send letter ‘Y’ to P2.
org 00H
;MAIN PROGRAM
SETB P1.7 ;make P1.7 an input
AGAIN: JB P1.2, OVER ;jump if P1.7=1
MOV P2, #’N’ ;SW=0, issue ‘N’ to P2
SJMP AGAIN ;keep monitoring
OVER: MOV P2,#’Y’ ;SW=1, issue ‘Y’ to P2
SJMP AGAIN ;keep monitoring
Example3:Aswitch is connected to pin PI .7 and an LED to pin P2.7. Write
a program to get the status of the switch and send it to the LED.
org 00H
;MAIN PROGRAM
SETB P1.7 ;make P1.7 an input
AGAIN: MOV C,P1.0 ;read the SW status into CF
MOV P2.7, C ;send the SW status to LED
SJMP AGAIN ;keep repeating
Note: The instruction “MOV P2.7, P1.0” is wrong since such an
instruction doesn’t exist. However, “MOV P2, P1” is a valid instruction.

More Related Content

PPTX
Weather forecasting
PPTX
Lifi data transmission
PPTX
Memories in digital electronics
PDF
Li-Fi Project Report
PPTX
Li-Fi technology
PPTX
From Trade To Territory (social science)
PPTX
Embedded system
Weather forecasting
Lifi data transmission
Memories in digital electronics
Li-Fi Project Report
Li-Fi technology
From Trade To Territory (social science)
Embedded system

What's hot (20)

PPT
Memory & I/O interfacing
PDF
Keypad Interfacing with 8051 Microcontroller
PPTX
8051 Microcontroller ppt
PPTX
8255 PPI
PPTX
LCD Interacing with 8051
PPTX
Interfacing Stepper motor with 8051
PDF
8051 interfacing
PPTX
8051 Microcontroller PPT's By Er. Swapnil Kaware
PPTX
Relay interfacing with 8051
PPTX
Architecture of 8051
PPT
8051 ch9-950217
PPT
Memory organization of 8051
PPT
8051 instruction set
PPTX
Directional couplers 22
PDF
PPTX
Power dissipation cmos
PPT
PPT
Addressing modes of 8051
PDF
ARM CORTEX M3 PPT
PDF
Unit 3 mpmc
Memory & I/O interfacing
Keypad Interfacing with 8051 Microcontroller
8051 Microcontroller ppt
8255 PPI
LCD Interacing with 8051
Interfacing Stepper motor with 8051
8051 interfacing
8051 Microcontroller PPT's By Er. Swapnil Kaware
Relay interfacing with 8051
Architecture of 8051
8051 ch9-950217
Memory organization of 8051
8051 instruction set
Directional couplers 22
Power dissipation cmos
Addressing modes of 8051
ARM CORTEX M3 PPT
Unit 3 mpmc
Ad

Similar to Switches and LEDs interface to the 8051 microcontroller (20)

DOC
Unit iv microcontrollers final
DOCX
Simple Automatic Water Level Controller
PPTX
Ppt on interfacing led and 7 segment with 8951
PPTX
Ppt on interfacing led and 7 segmentwith 8951
PPTX
dokumen.tips_ppt-on-interfacing-led-and-7-segment-with-8951 (1).pptx
PPTX
project
PPTX
ppt of automatic room light controller and BI directional counter
DOCX
Automatic street light controller
PDF
8051interfacing 190425062221
PPTX
Microcontroller ppt
DOCX
Battery level Indicator Circuit
DOC
pe lab manual
PDF
Electrónica: Probador de LOPT/FBT Flyback
PDF
PPTX
Microprocessor based Temperature Controller
PDF
Relay driver basic
DOCX
Fed vonverter project design and progress report
PPTX
Self Switching Power Supply
PDF
Advanced motion controls se25a40ac
PDF
Advanced motion controls se25a40
Unit iv microcontrollers final
Simple Automatic Water Level Controller
Ppt on interfacing led and 7 segment with 8951
Ppt on interfacing led and 7 segmentwith 8951
dokumen.tips_ppt-on-interfacing-led-and-7-segment-with-8951 (1).pptx
project
ppt of automatic room light controller and BI directional counter
Automatic street light controller
8051interfacing 190425062221
Microcontroller ppt
Battery level Indicator Circuit
pe lab manual
Electrónica: Probador de LOPT/FBT Flyback
Microprocessor based Temperature Controller
Relay driver basic
Fed vonverter project design and progress report
Self Switching Power Supply
Advanced motion controls se25a40ac
Advanced motion controls se25a40
Ad

More from University of Technology - Iraq (19)

PPTX
Security problems.pptx
PPTX
Information System (IS) life cycle.pptx
PPTX
Performance Evaluation for Software Defined Networking (SDN) Based on Adaptiv...
PPT
Ch12 microprocessor interrupts
PPTX
Performance and traffic management for WSNs
PPTX
IP address and Domain name
PDF
Computer science mcq alle books4u
PDF
Parallel Algorithms: Sort & Merge, Image Processing, Fault Tolerance
PPTX
Wavelet Transform and DSP Applications
PPTX
SCHEDULING DAGs WITHOUT CONSIDERING COMMUNICATION
PPTX
DSB-SC Demodulation using matlab
PDF
Main memory-2 (ch8,os)
PDF
8086 microprocessor lab manual
PPTX
Security problems.pptx
Information System (IS) life cycle.pptx
Performance Evaluation for Software Defined Networking (SDN) Based on Adaptiv...
Ch12 microprocessor interrupts
Performance and traffic management for WSNs
IP address and Domain name
Computer science mcq alle books4u
Parallel Algorithms: Sort & Merge, Image Processing, Fault Tolerance
Wavelet Transform and DSP Applications
SCHEDULING DAGs WITHOUT CONSIDERING COMMUNICATION
DSB-SC Demodulation using matlab
Main memory-2 (ch8,os)
8086 microprocessor lab manual

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
RMMM.pdf make it easy to upload and study
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Basic Mud Logging Guide for educational purpose
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
Week 4 Term 3 Study Techniques revisited.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial diseases, their pathogenesis and prophylaxis
RMMM.pdf make it easy to upload and study
Module 4: Burden of Disease Tutorial Slides S2 2025
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
TR - Agricultural Crops Production NC III.pdf
Cell Types and Its function , kingdom of life
Anesthesia in Laparoscopic Surgery in India
Basic Mud Logging Guide for educational purpose
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial disease of the cardiovascular and lymphatic systems
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Institutional Correction lecture only . . .
master seminar digital applications in india

Switches and LEDs interface to the 8051 microcontroller

  • 1. Switches and LEDs Interface to the 8051 Microcontroller Prepared by: Afrah Salman
  • 2. Switch Basics • A switch is an electrical component that can break an electrical circuit, interrupting the current or diverting it from one conductor to another. • If we directly connect a switch to one of the microcontroller port pins, the pin floats when the switch is open. Meaning, it is not at a fixed logic level 0v or 5v.
  • 5. Interfacing Switch • Fig. 1 shows how to interface the switch to microcontroller. A simple switch has an open state and closed state. However, a microcontroller needs to see a definite high or low voltage level at a digital input. A switch requires a pull-up or pull-down resistor to produce a definite high or low voltage when it is open or closed. A resistor placed between a digital input and the supply voltage is called a "pull-up" resistor because it normally pulls the pin's voltage up to the supply.
  • 7. LED Basics • Light Emitting Diodes are the semi conductor light sources. Commonly used LEDs will have a cut-off voltage of 1.7V and current of 10mA. When an LED is applied with its required voltage and current it glows with full intensity. The Light Emitting Diode is similar to the normal PN diode but it emits energy in the form of light. The color of light depends on the band gap of the semiconductor.
  • 9. Interface to the Microcontroller • Now we could go ahead and interface it to the microcontroller, but we would rather interface 8 switches and 8 LED's to two ports as shown in the schematic below.
  • 11. • As we can see the schematic has basic circuits for oscillator, reset and power connections for the microcontroller. • A DIP (dual in line package) Switch, array of 8 switches is connected to PORT3 AND 8 LEDs toPORT2. • Observe the RR1 component, it is array of 8 resistors in a single pack(SIP). It is as good as connecting 8 pull-up resistors as shown in figure 1. You could also use 8 discrete resistors as well.
  • 12. Interfacing Switch with 8051 • We now want to control the LED by using switches in 8051 Slicker Board. It works by turning ON a LED & then turning it OFF when switch is going to LOW or HIGH. The 8051 Slicker board has eight numbers of point LEDs, connected with I/O Port lines (P0.0 – P0.7) to make port pins high. Eight switches, connected with I/O port lines (P2.0 – P2.7) are used to control eight LEDs.
  • 13. Circuit Diagram to Interface Switch with 8051
  • 14. Example1:The following program will make the value of PIN3.1 keeps toggling (ON/OFF) after some delay. org 00H ;MAIN PROGRAM Toggle: MOV P3, #01H ;move 00000001 to PORT3 CALL delay ;execute delay MOV A, P3 ;move PORT3 value to accumulator CPL A ;complement PORT3 value MOV P3, A ;move 11111110 to PORT3 CALL delay ;execute delay SJMP Toggle
  • 15. ;DELAY SUB-ROUTINE delay: MOV R5, #10 ;load register R5 with 10 third: MOV R6, #200 ;load register R6 with 200 second: MOV R7, #200 ;load register R7 with 200 DJNZ R7, $ ;decrement R7 till it is zero DJNZ R6, second ;decrement R6 till it is zero DJNZ R5, third ;decrement R5 till it is zero ret ;go back to main program END
  • 16. Example2:Aswitch is connected to pin PI .7. Write a program to check the status of SW and perform the following: If SW=0, send letter ‘N’ to P2., If SW=1, send letter ‘Y’ to P2. org 00H ;MAIN PROGRAM SETB P1.7 ;make P1.7 an input AGAIN: JB P1.2, OVER ;jump if P1.7=1 MOV P2, #’N’ ;SW=0, issue ‘N’ to P2 SJMP AGAIN ;keep monitoring OVER: MOV P2,#’Y’ ;SW=1, issue ‘Y’ to P2 SJMP AGAIN ;keep monitoring
  • 17. Example3:Aswitch is connected to pin PI .7 and an LED to pin P2.7. Write a program to get the status of the switch and send it to the LED. org 00H ;MAIN PROGRAM SETB P1.7 ;make P1.7 an input AGAIN: MOV C,P1.0 ;read the SW status into CF MOV P2.7, C ;send the SW status to LED SJMP AGAIN ;keep repeating Note: The instruction “MOV P2.7, P1.0” is wrong since such an instruction doesn’t exist. However, “MOV P2, P1” is a valid instruction.