Documente Academic
Documente Profesional
Documente Cultură
I/O Interfacing
Dedicated instructions for IO operations (Isolated I/O) same instruction for memory and IO (memory-mapped I/O) MCS-51 (8051) is memory mapped
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-3
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-4
2. Interrupt driven method: interface chip interrupts the CPU when it data register is empty. CPU executes the ISR
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-5
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-6
Case-2:
Gives a logic 1 on switch close High current on switch close
Case-3:
Can damage port if 0 is output
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-7
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-8
Bouncing contacts
Contact:
Push-button switches Toggle switches Electromechanical relays
Make and break Contact normally open switch The effect is called "contact bounce" or, in a switch, "switch bounce.
Hardware Solution
An RC time constant to suppress the bounce The time constant has to be larger than the switch bounce
Vcc
OUT
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-10
Hardware Solution
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-11
Software Solution
Read the new state of switch N time Wait-and-see technique
When the input drops an appropriate delay is executed (10 ms) then the value of the line is checked again to make sure the line has stopped bouncing
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-12
Interfacing a Keypad
16 keys arranged as a 4X4 matrix
Place a 0 on R0 port Read C port If there is a 0 bit then the button at the column/row intersection has been pressed. Otherwise, try next row Repeat constantly
F
B 7 3
E
A 6 2
D
9 5 1
C 8 4 0
C1 C2 C3 C4 R1 R2 R3 R4
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-13
Interfacing a Keypad
scan: scan1: scan2: scan3: scan4: .. .. .. mov jnb jnb jnb jnb mov jnb P1,#EFH P1.0,db_0 P1.1,db_1 P1.2,db_2 P1.3,db_3 P1,#DFH P1.0,db_4
F B 7
E A 6
D 9 5
C 8 4
P1.7 P1.6 P1.5 P1.4
8051
0
P1.3 P1.2 P1.1 P1.0
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-14
Interfacing a Keypad
db_0: lcall jb mov ljmp lcall jb mov ljmp wt_10ms P1.0, scan1 A, #0 get_code wt_10ms P1.1, scan2 A, #1 get_code
db_1:
.. ..
get_code:
key_tab:
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-15
Case-2
Case-3
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-16
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-17
Common Anode
Connect cathode to the output
Common Cathode
Connect cathode to the output
Therefore, the common anode variety would be better for our interfacing needs.
hsabaghianb @ kashanu.ac.ir Microprocessors 6-18
Case 2 would be more appropriate Case 1 will produce different brightness depending on the number of LEDs turned on.
hsabaghianb @ kashanu.ac.ir Microprocessors 6-19
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-20
get_code:
he x 3f 30 5b 4f 66 6d
7s_tab:
0110
0111 1000 1001
01111101
00000111 01111111 01101111
a b f a g d b f a g d
7d
07 7f 6f
b
a f b f e e
a g d b
a g d b c f g b c f
a g f
a g
e
d
c
d
e
d
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-21
LCD Interfacing
Liquid Crystal Displays (LCDs)
cheap and easy way to display text Various configurations (1 line by 20 X char up to 8 lines X 80)
Integrated controller
The display has two register
command register data register
8 data pins D7:D0 RS: Data or Command Register Select R/W: Read or Write E: Enable (Latch data)
8
LCD controller
LCD Module
R/W = 1 Read
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-23
LCD Commands
The LCDs internal controller can accept several commands and modify the display accordingly. Such as:
Clear screen Return home Decrement/Increment cursor
After writing to the LCD, it takes some time for it to complete its internal operations. During this time, it will not accept any new commands or data.
We need to insert time delay between any two commands or data sent to LCD
hsabaghianb @ kashanu.ac.ir Microprocessors 6-24
Pin Description
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-25
Command Codes
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-26
LCD Addressing
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-27
LCD Timing
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-28
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-29
RW E RS
P3.3
P1.7-P1.0
D7-D0
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-30
mov A, command call cmd delay mov A, another_cmd call cmd delay mov A, #A call data delay mov A, #B call data delay . Command and Data Write Routines data:mov P1, A ;A is ascii data setb P3.3 ;RS=1 data clr P3.4 ;RW=0 for write setb P3.5 ;H->L pulse on E clr P3.5 ret cmd:mov P1,A ;A has the cmd word clr P3.3 ;RS=0 for cmd clr P3.4 ;RW=0 for write setb P3.5 ;H->L pulse on E clr P3.5 ret
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-31
Example
hsabaghianb @ kashanu.ac.ir
Microprocessors 6-32
8255 memory mapped to 8051 at address C000H base Control word for all ports as outputs in mode0
CR : 1000 0000b = 80H
A = C000H, B = C001H, C = C002H, CR = C003H
test:
repeat:mov DPTR,#C000H movx @DPTR, A inc DPTR movx @DPTR, A inc DPTR movx @DPTR, A cpl A acall MY_DELAY sjmp repeat
hsabaghianb @ kashanu.ac.ir
; ; ; ; ; ; ; ; ; ; ; ; ; ;
control word address of CR write control word will try to write 55 and AA alternatively address of PA write 55H to PA now DPTR points to PB write 55H to PB now DPTR points to PC write 55H to PC toggle A (55AA, AA55) small delay subroutine for (1)
Microprocessors 6-33