Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
64 views7 pages

IO Interfacing

This document discusses interfacing various input and output devices to a microcontroller. It describes interfacing LEDs, LCDs, relays, 7-segment displays, keypads, motors, ADC/DACs, and temperature sensors to an 89C51 microcontroller using embedded C programs. Sample programs are provided to interface a switch and LED, explaining how to handle switch bouncing in software using delays. Flowcharts and code are given to read the switch status and turn the LED on and off after a delay.

Uploaded by

47 Bhushan Bari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views7 pages

IO Interfacing

This document discusses interfacing various input and output devices to a microcontroller. It describes interfacing LEDs, LCDs, relays, 7-segment displays, keypads, motors, ADC/DACs, and temperature sensors to an 89C51 microcontroller using embedded C programs. Sample programs are provided to interface a switch and LED, explaining how to handle switch bouncing in software using delays. Flowcharts and code are given to read the switch status and turn the LED on and off after a delay.

Uploaded by

47 Bhushan Bari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Unit –IV

Interfacing Input and Output devices

___________________________________________________________________________

4.1 Interface the various input, output and special devices to the
microcontroller 89C51
4.2 Output Devices : LED, LCD, Relays, 7-Segment displays, multiplex
7-Segment display
4.3 Input Devices : Key, Matrix keyboard
4.4 Motor : Stepper motor, DC motor
4.5 ADC/DAC: 8 bit ADC/DAC (0808/09)
4.6 Sensor :Temperature sensor (LM35)

4a. Explain Interfacing of the given basic input/output device (s) to the
given microcontroller with embedded ‘C’ 'program.
4b. Explain Interfacing of the given LCD, matrix key board, multiplexed
7-Segment display, sensor to the given microcontroller with
embedded ‘C’ program.
4c. Explain Interfacing of DC motor to the given microcontroller to rotate
in the given direction using embedded ‘C’program.
4d. Explain Interfacing of given stepper motor with the microcontroller to
rotate in given direction, angle of rotation, with half step/full step with
embedded ‘C’program.
4e. Explain Interfacing of the given ADC/DAC to convert data with
the given microcontroller with embedded C program.

Electrical Switch:The switch is a basic input device, use to control the


operation of any output device using the microcontroller or control unit.
It basically breaks the electrical
circuit and interrupts the flow of current.

Figure 9.1: Switches

Connection of electrical Switch:


Positive Logic:  In this connection, Negative Logic: In this
a pull-down resistor is connected to connection, a pull-up resistor is
ground. When switch is pressed connected to Vcc. When switch is
then logic asserts high and when pressed then logic asserts low and
released the switch logic assert when released the switch logic
low. assert high.

Figure 9.2: Switch logic


Note: We may face the problem with the mechanical switch when we
pressed and release the switch then it oscillates. It’s called bouncing of
the switch. We can resolve the bouncing problem with the help of
hardware or software. In software, if we give the delay of few
milliseconds between the times, when we read the status of the switch
then we resolved the switch bouncing problem.

Light emitting diodes: LED has two leads cathode and anode. The length
of cathode leads is lesser than the length of anode but sometimes they
come in equal size. When the length of both leads cathode and anode are
equal in the size that time identification of anode and cathode can be
done by observing their filament, the cathode has broader filament than
the anode as shown in the Figure 9.3:

Figure 9.3 LED constructional diagram and its connections


Figure 9.4: 89C51 connection to LED and switch

SAMPLE PROGRAM 1: : Develop and execute embedded ‘C’


program to read the status of key and turn ON a LED connected to
port pin of 89C51 microcontroller and turn OFF after some delay.

Step 1: Algorithm
1. Initialize port pin P0.0 as input.
2. Initialize port pin P2.0 as output.
3. Read the status of key.
4. If key is closed then turn ON the LED.
5. Add some delay
6. Turn OFF the LED.
7. Repeat from step3.
Figure 9.7: Flowchart for Key and LED
Step 3: ‘C’ Language Program Comments
#include<reg51.h> /* Special function register
declarations */
/* for the intended 8051
derivative */
sbit LED_pin=P2^0; //Define LED PIN
sbit KEY_pin=P0^0; //Define key PIN

void delay_ms(unsigned int); //Function prototype declaration


void main (void)
{
KEY_pin=1;
LED_pin=0; //Make key pin input
LED_pin=1; //Make LED pin output
while(1) //Make LED off initially
{
if(KEY_pin == 0 )
{ //Iinfinite loop
LED_pin = 0;
delay_ms(200); //If key pressed
LED_pin = 1;
} //LED ON
} //Delay
} //LED OFF
void delay_ms(unsigned int k)
{
unsigned int i, j;
for(i=0;i<k;i++)
{ //Delay function
for(j=0;j<1275;j++);
}
}

You might also like