Program 3: Read Switch Inputs from Port B and Display on Port C Lower - 4.3 | EXPERIMENT NO. 3 TITLE: Parallel I/O Interfacing with 8085 (8255 Programmable Peripheral Interface) | Microcontroller Lab
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

Interactive Audio Lesson

Listen to a student-teacher conversation explaining the topic in a relatable way.

Understanding Port Configuration

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Today, we will learn how to read switch inputs from Port B of the 8255 and display the information on Port C Lower. Can anyone tell me what the first step in configuring the 8255 is?

Student 1
Student 1

I think we need to set a control word first, right?

Teacher
Teacher

Exactly! The control word configures the ports for input or output. For our program, we need to configure Port B as an input and Port C Lower as an output.

Student 2
Student 2

What is the control word for that configuration?

Teacher
Teacher

Great question! For this configuration, the control word would be 10011010 in binary or 9AH in hexadecimal. What do those bits represent?

Student 3
Student 3

Could we break that down? Like what each part means?

Teacher
Teacher

Of course! The first bit indicates it's in I/O mode, the next bits configure the functionality for Groups A and B, specifying directions. For our task, bits for Port B must indicate input. Generally, these kinds of configurations help remember what sections correspond to which ports.

Student 1
Student 1

That's helpful! How do we write this control word?

Teacher
Teacher

You will load the value into the accumulator and then output it to the control word register at address 83H. Let's summarize: You configure the ports by setting the control word and write it to register using assembly language.

Programming Example and Flow

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now, let’s look at the assembly code. The program starts at address 2000H. What do you think is the first instruction?

Student 2
Student 2

It would be to move the control word into the accumulator.

Teacher
Teacher

Correct! We use `MVI A, 9AH`. After that, we output it to the CWR using `OUT 83H`. Can anyone explain the next part?

Student 4
Student 4

We would need to read from Port B next using `IN 81H`, right?

Teacher
Teacher

Yes! That's right. What does that input instruction do for us?

Student 3
Student 3

It brings the state of the switches connected to Port B into the accumulator.

Teacher
Teacher

Exactly! After storing the data, we need to ensure we only keep the lower 4 bits for the LEDs. Can anyone remind me how we do that?

Student 1
Student 1

We use the `ANI 0FH` instruction to mask out the upper bits.

Teacher
Teacher

Great memory! Finally, we will output the result to Port C using `OUT 82H`. This flow is essential for displaying the switch states on the connected LEDs.

Expected Outcomes and Observations

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

After executing the program, what kind of behavior do you expect from the LEDs connected to Port C Lower?

Student 4
Student 4

They should match the state of the switches connected to Port B.

Teacher
Teacher

Exactly! If all switches are off, the LEDs should be off too, and if PB0 is on, PC0 should light up.

Student 2
Student 2

Is there a way to test different switch combinations?

Teacher
Teacher

Yes! You can record the states of the switches in a table format to verify the outputs against your expectations.

Student 3
Student 3

Can we predict how many unique combinations there are for the switches?

Teacher
Teacher

Sure! Since we have four switches, we can have 2^4 or 16 combinations of states. Always handy to know as you compare results!

Student 1
Student 1

This will really help us make sense of how the inputs affect outputs in our program.

Teacher
Teacher

Absolutely! This understanding is crucial for interfacing and control in microcontroller applications.

Introduction & Overview

Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.

Quick Overview

This section describes an experiment using the 8255 Programmable Peripheral Interface to read switch inputs from Port B and display the status on Port C Lower.

Standard

The objective is to configure Port B as an input port to read the state of switches and output that data to Port C Lower, thereby lighting up LEDs based on switch conditions. The section includes control word calculations, assembly code examples, and expected outcomes.

Detailed

Detailed Summary

In this section, the process of reading switch inputs from Port B and displaying them on Port C Lower using the 8255 Programmable Peripheral Interface (PPI) is outlined. The program objectives include configuring Port B as an input port to capture switch states and outputting this data to Port C Lower, activating corresponding LEDs. The control word calculation is critical, establishing the role of each port and the mode of operation. The detailed assembly code is provided to show how to implement this function using 8085 assembly language, along with an expected outcome, illustrating how LEDs reflect the state of connected switches. This demonstrates the effective utility of the 8255 in simple I/O operations, enhancing the understanding of data interfacing with microcontrollers.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Objective of Program 3

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Objective: To configure Port B as input and Port C Lower as output (Mode 0). Read the state of 4 switches connected to PB0-PB3, then output this 4-bit data to PC0-PC3 to display on LEDs.

Detailed Explanation

The objective of Program 3 is focused on reading the state of input switches connected to Port B and reflecting their state on output LEDs connected to Port C Lower. The program operates in Mode 0, which allows for basic input/output operations without handshaking.

Examples & Analogies

Think of this program as someone taking a poll by pressing buttons (the switches) to vote. Each button pressed updates a scoreboard (the LEDs), showing the current votes. This way, everyone can see the results in real-time.

Control Word Calculation

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Control Word Calculation (I/O Mode):
- D7 = 1 (I/O Mode)
- D6, D5 = 00 (Group A - Mode 0)
- D4 (Port A Direction) = 1 (Input - arbitrary as not used)
- D3 (Port C Upper Direction) = 1 (Input - arbitrary)
- D2 = 0 (Group B - Mode 0)
- D1 (Port B Direction) = 1 (Input)
- D0 (Port C Lower Direction) = 0 (Output)
- Resulting Control Word (Binary): 10011010b = 9AH (Hex)

Detailed Explanation

The Control Word defines how the ports of the 8255 PPI will operate. In this case, the control word is set such that Port B is configured as input, Port C Lower as output, and Port A is configured as input (though it won't be used). The control word, represented in binary as 10011010, translates to 9AH in hexadecimal, which the program sends to the 8255 to set these configurations.

Examples & Analogies

Imagine this control word as a remote control's settings. When you press a button on the remote, it sends specific settings to your television, like changing the channel or adjusting the volume. The control word assigns specific functions to the 8255's ports just like the remote assigns functions to the TV.

Assembly Code Explanation

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

; Program to read switches from Port B and display on Port C lower
; Starting Address: 2000H
ORG 2000H
; --- 8255 Initialization ---
MVI A, 9AH ; Load 8255 Control Word (Port A=In, B=In, C_L=Out, C_U=In)
OUT 83H ; Write Control Word to 8255 CWR
; --- Main Loop to Read and Display ---
READ_LOOP:
IN 81H ; Read data from Port B (connected to switches) into Accumulator
ANI 0FH ; Mask out higher nibble (keep only lower 4 bits for switches PB0-PB3)
OUT 82H ; Output Accumulator content to Port C (PC0-PC3 will show switch states)
JMP READ_LOOP; Jump back to READ_LOOP to continuously read

Detailed Explanation

This assembly code consists of several key sections: First, it initializes the 8255 PPI with the control word for the ports. Then, it enters a loop where it continuously reads the input from Port B using the 'IN' instruction, which captures the states of the switches into the Accumulator. The 'ANI' instruction masks any higher bits so only the relevant states of the first four switches are taken into account, and it outputs that data to Port C Lower to control the LEDs.

Examples & Analogies

Consider this loop as a teacher checking student attendance at a school. The teacher goes around the classroom (READ_LOOP) and checks if each student is present (the switches). Each student's presence or absence modifies the class roster displayed on the board (reflecting the lights on LEDs). The teacher keeps checking until class ends.

Expected Outcomes

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Expected Outcomes:
● LEDs connected to PC0-PC3 should reflect the exact binary state of the switches connected to PB0-PB3. For example, if PB0 and PB2 are ON (switches closed, assuming active high or pull-up/low logic), and PB1, PB3 are OFF, the LEDs on PC0 and PC2 should be ON.

Detailed Explanation

The expected outcome of the program is that the states of the switches directly correlate to the states of the LEDs on Port C Lower. If a switch is pressed (logic high), the corresponding LED should light up and if no switch is pressed (logic low), the LED should remain off. This real-time feedback allows users to see which switches are activated.

Examples & Analogies

Think of it like a light switch in your home. When you flip the switch, a light turns on in your room (like the LED) indicating that the switch is active. If you don't flip the switch, the light remains off, showing that the switch is inactive.

Definitions & Key Concepts

Learn essential terms and foundational ideas that form the basis of the topic.

Key Concepts

  • Port Configuration: Setting the appropriate bits in the control word to define each port's function.

  • I/O Operations: Reading input from Port B and outputting to Port C.

  • Switch States: Understanding how switch positions affect the LEDs connected to Port C.

Examples & Real-Life Applications

See how the concepts apply in real-world scenarios to understand their practical implications.

Examples

  • An example is reading the state of four switches attached to PB0 through PB3 to control the LEDs on PC0 to PC3.

  • When switches PB0 and PB2 are closed (ON), the corresponding LEDs on PC0 and PC2 should illuminate.

Memory Aids

Use mnemonics, acronyms, or visual cues to help remember key information more easily.

🎵 Rhymes Time

  • To read switches, set the word like so, / Output to LEDs where they glow.

📖 Fascinating Stories

  • Imagine a party where the lights only turn on when someone presses a switch. Each switch corresponds to a different LED, lighting up in response to the guests’ actions.

🧠 Other Memory Gems

  • Remember: CBOSS - Control word, B for input, O for output to C.

🎯 Super Acronyms

PICO – Port Input, Control Output – helps to recall that ports are configured based on input and control settings.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: Control Word

    Definition:

    An 8-bit command written to the 8255's Control Word Register to configure its ports.

  • Term: Accumulator

    Definition:

    The register in the microprocessor where intermediate arithmetic and logic results are stored.

  • Term: Input/Output (I/O)

    Definition:

    The process of sending or receiving data to or from external devices.

  • Term: LED

    Definition:

    Light Emitting Diode, a type of electronic component that produces light when an electric current passes through it.

  • Term: Masking

    Definition:

    A technique used to select certain bits of a binary value while ignoring others.