Mod 5 LED LCD Keypad ADC - DAC Full
Mod 5 LED LCD Keypad ADC - DAC Full
MICROCONTROLLERS (BECE204L)
Interfacing is one of the important concepts in microcontroller 8051 because the microcontroller is a
CPU that can perform some operation on a data and gives the output. However to perform the
operation we need an input device to enter the data and in turn output device displays the results of
the operation.
There are different type of input and output devices as for our requirement such as LEDs, LCDs,
7segment, ADC, keypad, motors, sensors etc.
Interfacing LED with 8051
LEDs are most commonly used in many applications for indicating the output.
They find huge range of applications as indicators during test to check the validity of
results at different stages.
They are very cheap and easily available in a variety of shape, color and size
7-Segment Display
ALP to display 0 to 9 in 7-segment
display which is connected to Port 1
LCD INTERFACING
LCD is finding widespread use replacing LEDs.
The declining prices of LCD.
It has ability to display numbers, characters, and
graphics.
Ease of programming for characters and graphics.
Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task
of refreshing the LCD.
16×2 LCD means that the are two rows in which 16 characters can be displayed per line, and
each character takes 5×7 matrix space on LCD.
The most common LCD controller is HITACHI 44780 which provides a simple interface
between the microcontroller and an LCD.
The commonly used alphanumeric displays are 16 * 1 (16 characters & single line), 16 * 2
(16 characters & double line) and 20 * 4 (20 characters per line & four lines).
Interfacing LCD with 8051
Table 12-1: Pin Descriptions for LCD
06 Shift cursor from left to right 14 Shift cursor position to the right
16 x 2 LCD 80 81 82 83 84 85 86 through 8F
C0 C1 C2 C3 C4 C5 C6 through CF
20 x 1 LCD 80 81 82 83 through 93
20 x 2 LCD 80 81 82 83 through 93
C0 C1 C2 C3 through D3
20 x 4 LCD 80 81 82 83 through 93
C0 C1 C2 C3 through D3
94 95 96 97 through A7
D4 D5 D6 D7 through E7
40 x 2 LCD 80 81 82 83 through A7
C0 C1 C2 C3 through E7
Solution: To send any of the commands to the LCD, make pin RS = 0. For data,
make RS = 1. Then send a high-to-low pulse to the E pin to enable the internal latch
of the LCD. This is shown in the code below.
Solution: ORG 0000H ;P1.0-P1.7 = D0-D7, P2.0 = RS, P2.1 = R/W, P2.2=E
MOVA,#38H
ACALL COMNWRT
ACALL DELAY
MOVA,#0EH
ACALL COMNWRT
ACALL DELAY
MOVA,#01H
ACALL COMNWRT
ACALL DELAY
MOVA,#06H
ACALL COMNWRT
ACALL DELAY
MOVA,#86H
ACALL COMNWRT
Interfacing Keypad with 8051
A keypad is used to take input from the user for further processing.
Here a 4 by 3 matrix keypad consisting of switches arranged in rows and columns is
interfaced to the microcontroller.
A 16 by 2 LCD is also interfaced for displaying the output
Interfacing concept
The interfacing concept of keypad is very simple. Every number of keypad is
assigned two unique parameters that are row and column (R, C).
Hence every time a key is pressed the number is identifying by detecting the row
and column numbers of keypad.
Initially all the rows are set/grounded to zero (‘0’) by the controller and columns are
scanned to check if any key is pressed. In case of no key is pressed the output of all
columns will be high (‘1’).
MATCH: CLR A
MOVC A, @A+DPTR ; get ASCII from table
MOV P0, A ; display pressed key
LJMP L1
ORG 300H
KCODE0: DB ‘0’, ‘1’ ;ROW 0
KCODE1: DB ‘2’, ‘3’ ; ROW 1
END
Assembly Language Program to interface 4X4 matrix Keyboard with 8051
ScanRow: MOV P1, #11111110B ; ground row 0
MOV P2, #0FFH ; make P2 input (column) MOV A, P2; read all columns
L1: MOV P1, #00H ; make P2 output (row) ANL A, #0FH
MOV A, P2 ; read all column CJNE A, #0FH, Row_0; key row 0, find column
MOV P1, #11111101B ; ground row 1
ANL A, #0FH;
MOV A, P2
CJNE A, #0FH, L2 ANL A, #0FH
SJMP L1 CJNE A, #0FH, Row_1; key row 1, find column
MOV P1, #11111011B ; ground row 2
L2: ACALL Delay ; call 20 ms delay MOV A, P2
ANL A, #0FH
CJNE A, #0FH, Row_2; key row 2, find column
MOV A, P2 ;
MOV P1, #11110111B ; ground row 2
ANL A, #0FH ; check if any key is pressed MOV A, P2
CJNE A, #0FH, ScanRow ; key pressed ANL A, #0FH
SJMP L1 scan row CJNE A, #0FH, Row_3 ; key row 3, find column
LJMP L1
Assembly Language Program to interface 4X4 matrix Keyboard with 8051
Row_0: MOV DPTR, #KCODE0 ; set DPTR = start of Row 0
SJMP FIND ; Find column key belongs to
Row_1: MOV DPTR, #KCODE1
SJMP FIND
Row_2: MOV DPTR, #KCODE2
SJMP FIND
Row_3: MOV DPTR, #KCODE3
SJMP FIND
MATCH: CLR A
MOVC A, @A+DPTR ; get ASCII from table
MOV P0, A ; display pressed key
LJMP L1
Interfacing ADC with 8051
ADCs (analog-to-digital converters) are among the most widely used devices for data
acquisition
A physical quantity, like temperature, pressure, humidity, and velocity, etc., is
converted to electrical (voltage, current) signals using a device called a transducer, or
sensor
An analog-to-digital converter is used to translate the analog signals to digital
numbers, so microcontroller can read them
ADC804
ADC804 IC is an analog-to-digital converter
It works with +5 volts and has a resolution of 8 bits
Conversion time is another major factor in judging an ADC. It is defined as the time
it takes the ADC to convert the analog input to a digital (binary) number
In ADC804 conversion time varies depending on the clocking signals applied to CLK R
and CLK IN pins, but it cannot be faster than 110 μs
Interfacing ADC with 8051
The voltage at Vref/2 (pin9) of ADC0804 can be externally adjusted to convert smaller input voltage spans to
full 8 bit resolution. Vref/2 (pin9) left open means input voltage span is 0-5V and step size is 5/255=19.6V.
Interfacing ADC with 8051
The circuit initiates the ADC to convert a given analogue
input , then accepts the corresponding digital data and
displays it on the LED array connected at P0.
For example, if the analogue input voltage Vin is 5V then
all LEDs will glow indicating 11111111 in binary which is
the equivalent of 255 in decimal.
AT89s51 is the microcontroller used here. Data out pins
(D0 to D7) of the ADC0804 are connected to the port
pins P1.0 to P1.7 respectively.
LEDs D1 to D8 are connected to the port pins P0.0 to
P0.7 respectively. Resistors R1 to R8 are current limiting
resistors.
In simple words P1 of the microcontroller is the input
port and P0 is the output port.
Control signals for the ADC (INTR, WR, RD and CS) are
available at port pins P3.4 to P3.7 respectively. Resistor
R9 and capacitor C1 are associated with the internal
clock circuitry of the ADC.
Preset resistor R10 forms a voltage divider which can be
used to apply a particular input analogue voltage to the
ADC.
Push button S1, resistor R11 and capacitor C4 forms a
debouncing reset mechanism.
Crystal X1 and capacitors C2,C3 are associated with the
clock circuitry of the microcontroller.
Interfacing ADC with 8051
Interfacing DAC with 8051
Digital to Analog converter (DAC) is a device, that is widely used for converting digital pulses to analog
signals.
There are two methods of converting digital signals to analog signals. These two methods are binary
weighted method and R/2R ladder method.
MC1408 (DAC0808) Digital to Analog Converter used. This chip uses R/2R ladder method. This method
can achieve a much higher degree of precision.
DACs are judged by its resolution. The resolution is a function of the number of binary inputs. The most
common input counts are 8, 10, 12 etc. Number of data inputs decides the resolution of DAC. So if there
are n digital input pin, there are 2n analog levels. So 8 input DAC has 256 discrete voltage levels
DAC0808
Digital inputs are converted to current.
The output current is known as Iout by connecting a resistor to the output to convert into voltage.
The total current provided by the Iout pin is basically a function of the binary numbers at the input
pins D0 - D7 (D0 is the LSB and D7 is the MSB) of DAC0808 and the reference current Iref provided into
the pin 14
Practically Iref current input is isolated by connecting it to an Op-Amp with Rf = 5KΩ as feedback
resistor
Interfacing DAC with 8051
Interfacing DAC with 8051