You are on page 1of 36

10/24/2019

ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH


TRƯỜNG ĐẠI HỌC BÁCH KHOA
KHOA ĐIỆN-ĐIỆN TỬ
BỘ MÔN KỸ THUẬT ĐIỆN TỬ

Embedded System Design


Chapter 7: Peripherals for embedded
systems
7.1 Digital parallel input / output
7.2 LCD interfacing
7.3 Analog input /output
7.4 Serial communication

Bộ Môn Kỹ Thuật Điện Tử - ĐHBK

1. Digital parallel input / output

• Commonly used input peripherals


– DIP switches, push-button keys, keyboards, and A/D converters
• DIP switch
– One side of the switch is tied high
• To a power supply through a resistor called a pull-up resistor
– The other side is grounded
– The logic level changes when the position is switched
• Push-button key
– Same as the DIP switch except that contact is momentary

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 2

1
10/24/2019

SWITCH ON I/O PORTS

very small the circuit waste a when the switch is open,


current needed large current the input floats to a noise-
sensitive

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 3

Switch Input

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 4

2
10/24/2019

Digital input for PIC

Active Low-Button Active High-Button


Input Input Transistor Input

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 5

Switch hardware debouncing

Switch hardware debounce


(a) without debounce capacitor
(b) with debounce capacitor
Ex: With a 10k pull-up resistor, a 10 nF
capacitor would give a time constant of 100 ms,
which should be more than adequate
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 66

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.

Bouncing in mechanical switches. When the switch opens


or closes, the mechanical pieces vibrate generating fast
contacts before settling. This transient normally lasts less
than 20 ms.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 7

Interfacing Dip Switches

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 8

4
10/24/2019

Test Circuit with Input Switch

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 9

Tests an input with IF Statement


// IFIN.C Tests an input
#include " 16F877A.h "
void main()
{
int x; // Declare variable
output_D(0); // Clear all outputs
while(1) // Loop always
{
x = input(PIN_C0); // Get input state
if(x = = 1)output_high(PIN_D0); // Change output
}
}

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 10

10

5
10/24/2019

Tests an input with conditional loop


// WHILOOP.C Input switch controls output flashing
#include " 16F877A.h "
#use delay (clock = 1000000) // MCU clock = 1 MHz
void main()
{
while(1)
{
while(input(PIN_C0)) // Repeat while switch open
{
output_high(PIN_D0);
delay_ms(300); // Delay 0.3s
output_low(PIN_D0);
delay_ms(500); // Delay 0.5s
}
output_low(PIN_D0); // Switch off LED
}
}

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 11

11

Tests an input with FOR loop


// FORLOOP.C Repeat loop a set number of times
#include " 16F877A.h "
#use delay (clock = 1000000)
void main() {
int x;
while(input(PIN_C0)) { } ; // Wait until switch closed
for (x = 0; x < 5; x ++) // For loop conditions
{
output_high(PIN_D0); // Flash sequence
delay_ms(500);
output_low(PIN_D0);
delay_ms(500);
}
while(1); // Wait for reset
}
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 12

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 13

13

The procedure to service matrix keypads

The procedure to service matrix keypads is as follows:


Step 1: Wait until the keypad is clear (due to an earlier key pressed).
Step 2: Detect that a new key has been pressed.
Step 3: Explore the matrix keypad to determine the key that was pressed in two
ways:
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 14

14

7
10/24/2019

Explore the matrix keypad


• Sequential exploration of rows. This method sets the first row to 0 and
reads all the columns. If none of the columns is read at 0 it means that the
pressed key is not in that row. Then the next row is set to 0, and the
columns are read again. This process is repeated until a 0 is found in a
column. This determines the row and column for the pressed key, thus
giving the exploration code for that key.
• Simultaneous exploration of rows and columns. This method sets all the
rows to 0 and reads all the columns. This detects the column that contains
the pressed key but not its row. Then the process is inverted: all the
columns are set to 0 and the rows are read. This detects the row that
contains the pressed key. This gives the row and column for the pressed
key, and thus the exploration code for the key.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 15

15

Fig. 12 Algorithm to read an N-row, M-column matrix keypad using


sequential exploration. The algorithm waits until a key is pressed and
Chapter 7 - p1 16
returns its position (row i, column j).

16

8
10/24/2019

16-key matrix keypad connected to port B

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 17

17

Digital Output for PIC

Current Sourcing Current Sinking

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 18

18

9
10/24/2019

LED ON I/O PORTS

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 19

19

LED Interface

(Current Sink
Mode)
Connecting an LED in
Current Source Mode

(Current
Source Mode)

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 20

20

10
10/24/2019

Digital Output for PIC


Higher Current Load Interface

Driving a Lamp Using a Transistor

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 21

21

Digital Output for PIC


Relay Interface

Driving an Inductive Driving a Mains Bulb Using a Relay


Load (e.g., a Relay)

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 22

22

11
10/24/2019

Using ULN (Driver IC)


•The ULN2803 can provides much higher drive-current.
•The ULN2803 also has internal diode protection that eliminates the need for
the fly-back diode
•ULN is better choice for simple design of circuit & PCB
The picture can't be display ed.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 23

23

Interfacing Seven-Segment LEDs as an Output (1/3)

• 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’.

• Two types of seven-segment LEDs


– Common anode (CA)
– Common cathode (CC)

decimal point

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 24

24

12
10/24/2019

Interfacing Seven-Segment LEDs


• In a common anode seven-
segment LED
– All anodes are connected
together to a power supply
and cathodes are
connected to data lines
• Logic 0 turns on a segment.
• Example: To display digit 1, all
segments except b and c
should be off.
• Byte 11111001 = F9H will
display digit 1.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 25

25

Interfacing Seven-Segment LEDs


• In a common cathode seven-
segment LED
– All cathodes are connected
together to ground and the
anodes are connected to
data lines
• Logic 1 turns on a segment.
• Example: To display digit 1, all
segments except b and c
should be off.
• Byte 00000110 = 06H will
display digit 1.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 26

26

13
10/24/2019

Example : Interfacing Seven-Segment LEDS to


PORTB and PORTC

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 27

27

Interfacing to Multiple 7-Segments (1/2)

Chapter 7 - p1 28

28

14
10/24/2019

Interfacing to Multiple 7-Segments (2/2)

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 29

29

Keypad Connection to the Microcontroller

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 30

30

15
10/24/2019

Class Assignment

Write a PIC C program to display keypad code on 7-segment LED

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 31

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 32

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.

A Typical Parallel LCD


• Fortunately, the CCS C language provides special commands for
displaying data on HD44780 or compatible LCDs
• All the user has to do is connect the LCD to the appropriate I/O ports
and then use these special commands to simply send data to the LCD.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 33

33

Alphanumeric LCD Interfacing


• Pinout Microcontroller

– 8 data pins D7:D0


– RS: Data or Command
E communications
R/W bus

Register Select RS
DB7–DB0
– R/W: Read or Write 8
– E: Enable (Latch data)
LCD
controller

• RS – Register Select LCD Module

– 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

4-bit mode LCD Connections to a PIC


Microcontroller

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 35

35

16F84 to LCD 8-bit Mode Circuit

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 36

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

• 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

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 37

37

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 38

38

19
10/24/2019

LCD - Cursor Addresses for Some LCDs

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 39

39

Hitachi 44780 Based LCD Types and Character Locations

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 40

40

20
10/24/2019

LCD Timing

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 41

41

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 42

42

21
10/24/2019

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 43

43

Interfacing Text LCD


• Problem statement
– Interface a 2-line x 20 character LCD module with the built-in
HD44780 controller to I/O ports of the PIC18 microcontroller
• Multi-LCDs refer to LCDs with different interfaces

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 44

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 0x30W=38

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 45

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 46

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

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 47

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

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 48

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 49

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

• Asserts RS high to select DR


• Writes into LCD by asserting the R/W signal low
• Asserts the E signal high and then low (toggles) to latch a data byte or an
instruction

LCD data
write waveform

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 50

50

25
10/24/2019

HD44780 Bus Timing

Read timing diagram

Write timing diagram


Chapter 7 - p1 51

51

Interfacing LCD (Write)

• 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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 52

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

Bộ môn Kỹ Thuật Điện Tử - ĐHBK


http://www.8051projects.net/lcd-interfacing/commands.php
Chapter 7 - p1 53

53

Display Data RAM (DDRAM)


• Display data RAM (DDRAM) stores display data represented in 8-bit character
codes. Its extended capacity is 80 x 8 bits, or 80 characters. The area in display data
RAM (DDRAM) that is not used for display can be used as general data RAM. See
Figure 1 for the relationships between DDRAM addresses and positions on the
liquid crystal display.

1-Line Display

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 2-Line


Chapter 7 - p1 Display 54

54

27
10/24/2019

LCD – 8-Bit Interface

Chapter 7 - p1 55

55

8-bit LCD Interface (1/2)

delay_ms(40); // wait for POR


lcd_write(lcd_Command_mode, 0x30);
// Set as 8 bit data mode
delay_ms(5); // Delay 5 ms
lcd_write(lcd_Command_mode, 0x30);
// Set as 8 bit data mode
delay_us(200); // Delay 200 us
lcd_write(lcd_Command_mode, 0x30);
// Set as 8 bit data mode

// CCS C

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 56

56

28
10/24/2019

8-bit LCD Interface (2/2)

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);

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 57

57

Ex: 8-bit LCD interface - HW

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 58

58

29
10/24/2019

Ex: 8-bit LCD interface - SW (1/3)


#include <16F877.h>
#use delay(clock=20000000)
#use fast_io (C)
#use fast_io (D)
#define lcd_RS pin_C1
#define lcd_RW pin_C0
#define lcd_EN pin_C2
#define lcd_Command_mode 0
#define lcd_Data_mode 1

void lcd_write(byte mode, byte data)


{ // 8-bit data mode
output_d(data);
output_bit(lcd_RS, mode); // mode = 0 --> COMMAND; 1 --> DATA
output_bit(lcd_RW,0) ; // write to register
output_bit(lcd_EN,1); // Enable LCD.
delay_ms(1);
output_bit(lcd_EN, 0); // Disable LCD.
delay_ms(1);
}
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 59

59

Ex: 8-bit LCD interface - SW (2/3)


void lcd_init() {
delay_ms(40);
lcd_write(lcd_Command_mode, 0x30); // Set as 8 bit data mode
delay_ms(5); // Delay 5 ms
lcd_write(lcd_Command_mode, 0x30); // Set as 8 bit data mode
delay_us(200); // Delay 200 us
lcd_write(lcd_Command_mode, 0x30); // Set as 8 bit data mode
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);
}
void lcd_write_string(byte position, char *ptr, int delay_time)
{ lcd_write(lcd_Command_mode, 0x80 | position );
while ( *ptr != 0)
{
lcd_write(lcd_Data_mode, *ptr++);
delay_ms(delay_time);
}
}
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 60

60

30
10/24/2019

Ex: 8-bit LCD interface - SW (3/3)


void main() { // 4-bit mode LCD interface ( 2 x 16)
char text1[]="Hello the world!";
char text2[]="Number: ";
char text3[]="0123456789";
char *ptr;
set_tris_c(0x00); // Port C : output
set_tris_d(0x00); // Port D : output
lcd_init();
lcd_write(lcd_Command_mode, 0x0E);
lcd_write_string(0x00, text1, 20); // First line
lcd_write_string(0x40, text2, 20); // Second line
ptr = text3;
while (1)
{ if (*ptr == 0)
ptr = text3;
lcd_write(lcd_Command_mode, 0x80 | 0x48 );
lcd_write(lcd_Data_mode, *ptr++);
delay_ms(100);
}
}
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 61

61

LCD – 4-Bit Interface

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 62

62

31
10/24/2019

4-bit LCD interface - HW


U1
13 33 LCD1
OSC1/CLKIN RB0/INT LM016L
14 34
OSC2/CLKOUT RB1
1 35
MCLR/Vpp/THV RB2
36
RB3/PGM
2 37
RA0/AN0 RB4
3 38
RA1/AN1 RB5
4 39
RA2/AN2/VREF- RB6/PGC
5 40
RA3/AN3/VREF+ RB7/PGD
6
RA4/T0CKI

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

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 63

63

4-bit LCD interface


#include <16F877.h> char *ptr;
#use delay(clock=20000000) set_tris_d(0x00);
#use fast_io (D) lcd_init();
ptr = text3;
#define LCD_ENABLE_PIN PIN_E0 lcd_gotoxy(1,1);
#define LCD_RS_PIN PIN_E1 // lcd_putc("Hello the world!");
#define LCD_RW_PIN PIN_E2 printf(lcd_putc,"%s",text1);
#define LCD_DATA4 PIN_D4 lcd_gotoxy(1,2);
#define LCD_DATA5 PIN_D5 printf(lcd_putc,"%s",text2);
#define LCD_DATA6 PIN_D6 while (1)
#define LCD_DATA7 PIN_D7 { if (*ptr == 0)
#include <LCD.C> ptr = text3;
void main() { // 4-bit mode LCD ( 2 x 16) lcd_gotoxy(8,2);
char text1[]="Hello the world!"; lcd_putc(*ptr++);
delay_ms(100);
char text2[]="Number: "; }
char text3[]="0123456789"; }
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 64

64

32
10/24/2019

Using Library LCD.C


• Define LCD pins:
#define LCD_ENABLE_PIN PIN_E0
….
(don’t need to define LCD pins if the default pins are used)
• Functions
– lcd_init(): Must be called before any other function.
– lcd_putc(c): Will display c on the next position of the LCD.
• \f Clear display
• \n Go to start of second
• \b Move back one position
– lcd_gotoxy(x,y): Set write position on LCD (upper left is 1,1)
– lcd_getc(x,y): Returns character at position x,y on LCD

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 65

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.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 66

66

33
10/24/2019

Ex: MILFORD Serial LCD Interface – HW

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 67

67

Serial LCD

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 68

68

34
10/24/2019

Serial LCD
• Control Codes

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 69

69

Serial LCD

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 70

70

35
10/24/2019

Class Assignment

Write a PIC C program for the calculator with 4 basic operators: + - * /

Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 7 - p1 71

71

36

You might also like