Professional Documents
Culture Documents
Embedded System Design: 1. Digital Parallel Input / Output
Embedded System Design: 1. Digital Parallel Input / Output
1
10/24/2019
Switch Input
2
10/24/2019
3
10/24/2019
Software Debouncing
• Debouncing the key
– Software technique
• Wait for 20 ms.
• Read the port pin again.
• If the reading is still 0 (for eg..) , it
indicates that a key is pressed.
4
10/24/2019
10
5
10/24/2019
11
12
6
10/24/2019
Matrix Keypads
• Matrix keypads consist of keys interconnected in the shape of a matrix.
Each key is a simple mechanical switch located at the crossing between the
matrix rows and columns.
13
14
7
10/24/2019
15
16
8
10/24/2019
Fig.13 A 16-key matrix keypad connected to port B in a PIC. Diodes are used to
avoid short circuits between two exploration lines if two or more keys in the same
column are pressed simultaneously. This configuration uses the internal pull-up
(not shown) available in port B to keep a logic 1 in the return lines when no keys
are pressed.
17
18
9
10/24/2019
19
LED Interface
(Current Sink
Mode)
Connecting an LED in
Current Source Mode
(Current
Source Mode)
20
10
10/24/2019
21
22
11
10/24/2019
23
• Seven-segment LEDs
– Often used to display BCD numbers (1 through 9) and a few alphabets
– A group of eight LEDs physically mounted in the shape of the number
eight plus a decimal point)
– Each LED is called a segment and labeled as ‘a’ through ‘g’.
decimal point
24
12
10/24/2019
25
26
13
10/24/2019
27
Chapter 7 - p1 28
28
14
10/24/2019
29
30
15
10/24/2019
Class Assignment
31
2. Interface LCD
• LCDs (liquid-crystal displays) are alphanumeric displays
which are frequently used in microcontroller-based
applications.
– Parallel LCDs are connected to the microcontroller I/O ports
using 4 or 8 data wires and data is transferred from the
microcontroller to the LCD in parallel form.
– Serial LCDs are connected to the microcontroller using only
one data line and data is transferred to the LCD using the
standard RS232 asynchronous data communication protocols.
Serial LCDs are easier to use but they usually cost more than
the parallel ones.
32
16
10/24/2019
Parallel LCDs
• Following figure shows a typical parallel LCD. The programming of a
parallel LCD is usually a complex task and requires a good understanding
of the internal operation of the LCDs,including the timing requirements.
33
Register Select RS
DB7–DB0
– R/W: Read or Write 8
– E: Enable (Latch data)
LCD
controller
– RS = 0 Command Register
– RS = 1 Data Register
• R/W = 0 Write, R/W = 1 Read
• E – Enable
– Used to latch the data present on the data pins.
• D0 – D7
– Bi-directional data/command pins.
– Alphanumeric characters are sent in ASCII format.
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 34
34
17
10/24/2019
35
36
18
10/24/2019
LCD Commands
• The LCD’s internal controller can accept several
commands and modify the display accordingly. These
commands would be things like:
– Clear screen
– Return home
– Decrement/Increment cursor
37
38
19
10/24/2019
39
40
20
10/24/2019
LCD Timing
41
42
21
10/24/2019
43
44
22
10/24/2019
Converting to ASCII
• The LCD can represent characters in ASCII
• For example number 0x08 must be converted to 0x38
• To perform this:
– If W=0x08 then ASCII=XORLW 0x30W=38
45
Interfacing LCD
• Hardware
– 20 x 2-line LCD displays (two lines
with 20 characters per line)
– LCD has a display Data RAM
(registers) that stores data in 8-bit
character code.
– Each register in Data RAM has its
own address that corresponds to
its position on the line. PICDEMO
• The address range for Line 1 is 00
to 13H and Line 2 is 40H to 53H.
46
23
10/24/2019
Interfacing LCD
• Driver HD77480
– Three control signals:
• RS – Register Select (RA3)
• R/W – Read/Write (RA2)
• E – Enable (RA1)
– Three power connections
• Power, ground, and the
variable register to
control the brightness
47
Interfacing LCD
• Can be interfaced either in the 8-bit mode or the 4-bit
mode
– In the 8-bit mode, all eight data lines are connected for data
transfer
– In the 4-bit mode, only four data lines (DB7-DB4 or DB3-DB0)
are connected and two transfers per character (or instruction)
are needed
• Driver (HD77480) has two 8-bit internal registers
– Instruction Register (IR) to write instructions to set up LCD
– Data Register (DR) to write data (ASCII characters)
IR REGISTER
DR REGISTER
48
24
10/24/2019
Interfacing LCD
• LCD Operation
– When the MPU writes an instruction to IR or data to DR, the
controller:
• Sets the data line DB7 high as a flag indicating that the controller is
busy completing the operation
• Sets the data line DB7 low after the completion of the operation
– The MPU should always check whether DB7 is low before
sending an instruction or a data byte
– After the power up, DB7 cannot be checked for the first two
initialization instructions.
49
Interfacing LCD
• Writing to or reading from LCD
• The MPU:
• Asserts RS low to select IR
• Reads from LCD by asserting the R/W signal high
• Asserts the E signal high and then low (toggles) to latch a data byte or an
instruction
LCD data
write waveform
50
25
10/24/2019
51
• Software
– To write into the LCD, the program should:
• Send the initial instructions (commands) before it can
check DB7 to set up the LCD in the 4-bit or the 8-bit
mode.
• Check DB7 and continue to check until it goes low.
• Write instructions to IR to set up the LCD parameters
such as the number of display lines and cursor status.
• Write data to display a message.
52
26
10/24/2019
Resetting LCD
• In 4-bit mode the data is sent in nibbles
– First we send the higher nibble and then the lower nibble.
• To enable the 4-bit mode of LCD, we need to follow special
sequence of initialization that tells the LCD controller that user
has selected 4-bit mode of operation:
– Wait for about 20mS
– Send the first init value (0x30)
– Wait for about 10mS
– Send second init value (0x30)
– Wait for about 1mS
– Send third init value (0x30)
– Wait for 1mS
– Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)
– Wait for 1mS
53
1-Line Display
54
27
10/24/2019
Chapter 7 - p1 55
55
// CCS C
56
28
10/24/2019
lcd_write(lcd_Command_mode, 0x38);
lcd_write(lcd_Command_mode, 0x08);
lcd_write(lcd_Command_mode, 0x01);
// Display Clear
lcd_write(lcd_Command_mode, 0x06);
57
58
29
10/24/2019
59
60
30
10/24/2019
61
62
31
10/24/2019
VDD
VSS
VEE
RW
7 15
RS
D0
D1
D2
D3
D4
D5
D6
D7
RA5/AN4/SS RC0/T1OSO/T1CKI
E
16
RC1/T1OSI/CCP2
8 17
RE0/AN5/RD RC2/CCP1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
9 18
RE1/AN6/WR RC3/SCK/SCL
10 23
RE2/AN7/CS RC4/SDI/SDA
24
RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT
19
RD0/PSP0
20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877
63
64
32
10/24/2019
65
Serial LCD
• The LCD has its own controller, which is compatible with the
Hitachi 44780 MCU, the standard for this interface.
• When the system is started, the LCD takes some time to initialize
itself; its own MCU needs time to get ready to receive data. A
delay of about 500 ms should be allowed in the main controller
before attempting to access the LCD.
• The program uses library routines to generate the RS232 output,
which are called up by the directive #use RS232.
• The baud rate must be specified and the send (TX) and receive
(RX) pins specified as arguments of this directive.
• The directive must be preceded by a #use delay, which specifies
the clock rate in the target system.
66
33
10/24/2019
67
Serial LCD
68
34
10/24/2019
Serial LCD
• Control Codes
69
Serial LCD
70
35
10/24/2019
Class Assignment
71
36