Lecture Slide 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Interfacing with 8051

By
Dr. Supratim Gupta
Part-0: RTOS
RTOS in the 8051: Overall Structure

Address Vectoring:
.Org 0000H
sjmp Main
.Org 000BH
sjmp TM0
Information to Assembler
Caution: The syntax is
Macros:
tickN .reg 3FH
assembler specific
INT0_edg .reg TCON.0
IE_cont .equal 81H

Initialization Module:
Main: mov IE,#IE_cont
setb INT0_edg
RTO
S Run Module: Interrupt Module:
Loop: acall KBD TM0: cpl P1.0
sjmp Loop reti

Foreground/Non-Time Background/ Time


Critical Tasks Critical Tasks
RTOS in the 8051

INITIALIZATION MODULE

Resource for time interval generation:


Timer0 or Timer1

Design Issues:
 Mode of timer (16 or 8-
bit) tim_mod .equal 02h
mov TMOD, #tim_mod

 Computation of content to be used for initialization of timer


RTOS in the 8051
Time Slot Generation using single timer interrupt by multiplying factor with basic
timer interrupt interval
TM0: push ACC
push PSW
;----------Basic time interval------------------
tm_0: mov A,tickN
cjne A,#1,tm_1
;----------Basic T = time interval*tickN------------

mov tickN, #Tick ;Re-initialize for next T sec.


sjmp back
tm_1: dec ACC
mov tickN,A
back: pop PSW
pop ACC
reti
RTOS in the 8051

 Configuration of ports as input or output


mov P0, #FFh ; Set port0 as input port
mov P1, #00h ; Set port1 as output

 Address Vectoring
.org 0
ajmp main
.org 000bh
ajmp TM0 ;jump to timer0 routine
RTOS in the 8051

RUN
MODULE

Consists of infinite loop

main: acall level1 ;jump to service routine for foreground task


sjmp main
Interrupt

PROGRAM EXECUTION WITHOUT


INTERRUPT
Time

PROGRAM EXECUTION WITH


INTERRUPT

Time
ISR: Interrupt Service Routine
Part-1: Interfacing Keys
Keyboard Configuration

 Lead-per-Key

 Matrix Keypad

 Coded Keyboard
Keyboard Configuration: Lead-per-Key
Keyboard Configuration: Matrix
Keyboard Configuration: Coded Keyboard
Robust Keyboard Operations: Human Factors

 To guard against bouncing of push button or accidental key press

 To guard against multiple & simultaneous key press and release in arbitrary
sequence

 To guard against key press and held for longer duration

 To guard against rapid key press


Robust Keyboard Operations: Bouncing
Robust Keyboard Operations: Hardware Solution

Starting with the switch open


• The capacitor C1 will charge via R1 and D1
• In time, C1 will charge and Vb will reach within 0.7V
of Vcc.
• Therefore the output of the inverting Schmitt trigger
will be a logic 0.
Now close the switch
• The capacitor will discharge via R2.
• In time, C1 will discharge and Vb will reach 0V.
• Therefore the output of the inverting Schmitt trigger
will be a logic 1.
Robust Keyboard Operations: Hardware Solution

Schmitt Trigger

Output Voltage Vs. Input Voltage


Robust Keyboard Operations: Software Solution

 De-bounce/Accidental Key hit: To wait until a time interval –longer than the
manufacturer’s specification –lapses during both key press & release.

 Multiple Key press: To use only a valid key patterns –all other patterns will be
ignored; the first valid key patterns will be accepted

 Key Hold: To identify valid key press if the same valid pattern exists after the
de-bounce delay

 Rapid Key hit: Keys are scanned at a rate faster than human reaction time
The Algorithm for keyboard Interface

 Step1: Check if any key is pressed else return to main routine

 Step 2: Provide a time delay for de-bouncing (generally 20ms)

 Step 3: Check if same switch is remained pressed else return to main routine

 Step 4: Check if valid key pattern is pressed else return to main routine

 Step 5: Act on the key pressed and return to main routine


Robust Keyboard Operations: Software Solution

 Key scanning via polling: May sluggish, but usable for small keypad & less
number of multi-task environment

 Key scanning via interrupt: CPU will scan keys when interrupted; Optimal for
large key board & larger number of multi-tasking environment
Robust Keyboard Operations: Embedded Solution

Circuit connection for Lead-per-key scan via interrupt


Robust Keyboard Operations: Embedded Solution

Circuit connection for Coded key scan via interrupt


Robust Keyboard Operations: Embedded Solution

Circuit connection for Coded key scan via timer interrupt


Part-2: ADC & DAC
ADC Interfacing: ADC0809
25
ADC Interfacing: Bipolar Signal
26

To ADC Channel

Pre-conditioning Circuit
DAC Interfacing: DAC0808
27

𝐴 𝐴 𝐴 𝑉 𝐴 𝐴 𝐴
𝐼 =𝐼 + + …+ 𝐼 = + + …+
2 4 256 𝑅 2 4 256
DAC Interfacing: DAC0808
28

𝐴 𝐴 𝐴
𝐼 =𝐼 + + …+
𝑅 2 4 256

𝑉 𝐴 𝐴 𝐴
𝑅 𝐼 = + + …+
𝑅 2 4 256

𝑉 𝐴 𝐴 𝐴
𝑉 = + + …+ 𝑅
𝑅 2 4 256
DAC Interfacing: Bipolar output signal
29

I0
DAC0809

Post-conditioning of DAC output


Part-4: Interfacing Displays
Display Units

7-Segment LED Display

LCD Display
7-Segment Display
7-Segment Display: Single Unit

Common Anode/Cathode

Controlling the contrast


7-Segment Display: Multiple Units
The Algorithm for 7-Segment LED Display

 Step1: Get the content to be displayed in Hex

 Step 2: Convert the HEX number to BCD

 Step 3: Use index addressing –Base address + index (the nibbles of BCD no.) –
to a look up table for fetching code for 7-Segment LEDs

 Step 4: Send the code to Port where the unit(s) is (are) connected
Part-5: Device Communication
Device Communication Modes

 Parallel communication implies sending a whole byte (or more) of data over
multiple parallel wires

 Serial communication implies sending data bit by bit over a single wire

 Asynchronous: Universal asynchronous receiver/transmitter (UART Standard)


 Synchronous: Serial peripheral interface (SPI Standard)
Asynchronous Serial Communication
 With asynchronous communication, the transmitter and receiver do not
share a common clock

Add: Start, Stop, Parity Bits Remove: Start, Stop, Parity Bits

Transmitter + – Receiver
Data

1 byte-wide Data 1 byte-wide Data

The Transmitter The Receiver

 Shifts the parallel data onto the  Extracts the data using its own clock
serial line using its own clock
 Converts the serial data back to the
 Also adds the start, stop and parallel form after stripping off the
parity check bits start, stop and parity bits
Asynchronous Serial Communication
Start Bit Parity Bit 1 or 2 Stop Bits

D0 D1 D2 D3 D4 D5 D6 D7

1 Asynchronous Byte

 Baud rate—the bit rate of the serial port

 Throughput—actual data transmitted per sec (total bits transmitted—overhead)


 Example: 115200 baud = 115200 bits/sec
 If using 8-bit data, 1 start, 1 stop, and no parity bits, the effective
throughput is: 115200 * 8 / 10 = 92160 bits/sec
Serial Communication: Configuring 8051
Serial Communication: Configuring 8051
Serial Communication: Configuring 8051
Serial Communication: Configuring 8051

Timer 2 in Baud Rate Generation Mode


Serial Communication: Configuring 8051
Serial Communication: Programming 8051
Serial Communication between 8051 & PC
Serial Communication: Max232
Example of LCD Display with Temperature sensor

You might also like