You are on page 1of 23

8/9/2016

I HC QUC GIA TP.H CH MINH


TRNG I HC BCH KHOA
KHOA IN-IN T
B MN K THUT IN 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 Mn K Thut in T - HBK

7.3.AnalogInput
Allowsanexternalvoltagetobeconvertedtodigital
form,storedandprocessed
Thistypeofinputoccursindataloggers,control
systems,digitalaudioandsignalprocessors
ThePICmicrocontrollersisdesignedspecificallyforhigh
speedanalogsignalprocessing

B mn K Thut in T - HBK Chapter 7 - p2 2

1
8/9/2016

AnaloginputwithPIC16Series
Device Pins Features
16F873A 28 3 parallel ports,
16F876A 3 counter/timers,
2 capture/compare/PWM,
2 serial,
5 10-bit ADC,
2 comparators
16F874A 40 5 parallel ports,
16F877A 3 counter/timers,
2 capture/compare/PWM,
2 serial,
8 10-bit ADC,
2 comparators

B mn K Thut in T - HBK Chapter 7 - p2 3

ThePIC16F87XAADCmodule

Functional blocks for the A/D converter in medium-end PIC microcontrollers. A/D,
successive approximation analog-to-digital converter; SHA, sample-and-hold
Chapter 7 - p2 4
amplifier; AMUX, analog multiplexer.

2
8/9/2016

AnalogSetup
U1
ThePIC16F877haseightanalog 13
OSC1/CLKIN RB0/INT
33
14 34
OSC2/CLKOUT RB1
inputs:RA0,RA1,RA2,RA3, 1
MCLR/Vpp/THV RB2
35
36
RB3/PGM
RA5,RE0,RE1,RE2being 2
3
RA0/AN0 RB4
37
38
RA1/AN1 RB5
renamedAN0toAN7. 4
5
RA2/AN2/VREF-
RA3/AN3/VREF+
RB6/PGC
RB7/PGD
39
40
6
RA4/T0CKI
7 15
RA5/AN4/SS RC0/T1OSO/T1CKI
16
RC1/T1OSI/CCP2
8 17
RE0/AN5/RD RC2/CCP1
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
B mn K Thut in T - HBK Chapter 7 - p2
PIC16F877
5

CCSCAnalogInputFunctions

B mn K Thut in T - HBK Chapter 7 - p2 6

3
8/9/2016

CCSCAnalogInputFunctions

B mn K Thut in T - HBK Chapter 7 - p2 7

CCSCAnalogInputFunctions

B mn K Thut in T - HBK Chapter 7 - p2 8

4
8/9/2016

Chapter 7 - p2 9

Example
U1
13 33
RV1 14
OSC1/CLKIN RB0/INT
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
1k 6
RA4/T0CKI
7 15
RA5/AN4/SS RC0/T1OSO/T1CKI
16
RC1/T1OSI/CCP2
8 17
RE0/AN5/RD RC2/CCP1
9 18
RE1/AN6/WR RC3/SCK/SCL
10 23
RE2/AN7/CS RC4/SDI/SDA
24
RC5/SDO
25 LCD1
RC6/TX/CK
26
RC7/RX/DT VDD
19
RD0/PSP0 RXD
20
RD1/PSP1
21
RD2/PSP2 VSS
22
RD3/PSP3
27 MILFORD-2X16-BKP
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877

B mn K Thut in T - HBK Chapter 7 - p2 10

5
8/9/2016

Example

B mn K Thut in T - HBK Chapter 7 - p2 11

Voltagemeasurement
RV5(1)
V=2.71739
LCD1
R3 VDD

120R RXD

R1 VSS
680R
RV5 MILFORD-2X16-BKP

U1(RA3/AN3/VREF+)
V=2.55838
RV4 U1
1k 13 33
OSC1/CLKIN RB0/INT
14 34
RV3 1
OSC2/CLKOUT RB1
35
MCLR/Vpp/THV RB2
36
RB3/PGM
1k 2 37
RA0/AN0 RB4
3 38
RA1/AN1 RB5
4 39
RA2/AN2/VREF- RB6/PGC
1k 5 40
RA3/AN3/VREF+ RB7/PGD
6
RA4/T0CKI
7 15
RV1 RA5/AN4/SS RC0/T1OSO/T1CKI
16
RC1/T1OSI/CCP2
8 17
RV6 RV2 9
RE0/AN5/RD RC2/CCP1
18
RE1/AN6/WR RC3/SCK/SCL
10 23
RE2/AN7/CS RC4/SDI/SDA
1k 24
RV7 RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT
1k
RV8 19
RD0/PSP0
1k 20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
1k R2 RD4/PSP4
27
4k7 28
RD5/PSP5
29
RD6/PSP6
1k D1 RD7/PSP7
30

BZX79C2V7 PIC16F877

B mn K Thut in T - HBK Chapter 7 - p2 12

6
8/9/2016

Voltagemeasurement

B mn K Thut in T - HBK Chapter 7 - p2 13

7.3.AnalogOutput
Basic digital to analogue converter

a) general DAC hardware b) output voltage

B mn K Thut in T - HBK Chapter 7 - p2 14

7
8/9/2016

DAC

B mn K Thut in T - HBK Chapter 7 - p2 15

DACCircuit
Typicalapplication

A1 A2 A8
Vo 10V
2 4 256

B mn K Thut in T - HBK Chapter 7 - p2 16

8
8/9/2016

Ex:DAC0808&SerialDAC

B mn K Thut in T - HBK Chapter 7 - p2 17

WaveformGenerator

B mn K Thut in T - HBK Chapter 7 - p2 18

9
8/9/2016

WaveformGeneratorSourceCode(1/3)

B mn K Thut in T - HBK Chapter 7 - p2 19

WaveformGeneratorSourceCode(2/3)

B mn K Thut in T - HBK Chapter 7 - p2 20

10
8/9/2016

WaveformGeneratorSourceCode(3/3)

B mn K Thut in T - HBK Chapter 7 - p2 21

ClassAssignment
Designasystemtoreadtemperaturedatafromthe
sensorLM35,andshowtheresultonLCD

LCD1
LM016L
VDD
VSS

VEE

RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
E
1
2
3

4
5
6

7
8
9
10
11
12
13
14

B mn K Thut in T - HBK Chapter 7 - p2 22

11
8/9/2016

Serialcommunication
Serial transmission of binary data consists of sending the bits of a word one
by one in a consecutive form and using the same pins.

Parallel vs. Serial IO

B mn K Thut in T - HBK Chapter 7 - p2 23

simplexvshalfduplexvsfullduplex

B mn K Thut in T - HBK Chapter 7 - p2 24

12
8/9/2016

SerialCommunication

1.PIC16USARTSerialLink
2.PIC16SPISerialBus
3.I2CSerialBus

B mn K Thut in T - HBK Chapter 7 - p2 25

USART
Theuniversalsynchronous/asynchronousreceivetransmit(USART)deviceis
typicallyusedinasynchronousmodetoimplementoffboard,onetoone
connections.
Thetermasynchronousmeansnoseparateclocksignalisneededtotimethe
datareception,soonlyadatasend,datareceive,andgroundwiresare
needed.
Itisquickandsimpletoimplementifalimiteddatabandwidthisacceptable.

USART Operation

B mn K Thut in T - HBK Chapter 7 - p2 26

13
8/9/2016

USART
RS232driver
MAX232

USART RS232 Signal

B mn K Thut in T - HBK Chapter 7 - p2 27

USARTwithPICmicrocontroller
ThePIChasadedicatedhardwareRS232port,
butCCSCallowsanypintobesetupasan
RS232port,providingfunctionstogeneratethe
signalsinsoftware.

(a) Connection between two PICs (b) Synchronous mode connection. CK is


in asynchronous mode the clock pin, output in the master device
and input in the slave device

B mn K Thut in T - HBK Chapter 7 - p2 28

14
8/9/2016

CCSRS232SerialPortFunctions

B mn K Thut in T - HBK Chapter 7 - p2 29

RS232PeriperalSimulation

B mn K Thut in T - HBK Chapter 7 - p2 30

15
8/9/2016

Theprogram

B mn K Thut in T - HBK Chapter 7 - p2 31

Outline

1.PIC16UARTSerialLink
2.PIC16SPISerialBus
3.I2CSerialBus

B mn K Thut in T - HBK Chapter 7 - p2 32

16
8/9/2016

SPIBus
Theserialperipheralinterface(SPI)busprovideshighspeed
synchronousdataexchangeoverrelativelyshortdistances
(typicallywithinasetofconnectedboards),usingamaster/slave
systemwithhardwareslaveselection
Oneprocessormustactasamaster,generatingtheclock.Others
actasslaves,usingthemasterclockfortimingthedatasendand
receive.
Theslavescanbeothermicrocontrollersorperipheralswithan
SPIinterface.
TheSPIsignalsare:
SerialClock(SCK)
SerialDataIn(SDI)
SerialDataOut(SDO)
SlaveSelect(!SS)
B mn K Thut in T - HBK Chapter 7 - p2 33

SPIBus

SPI Connection

SPI Signals

B mn K Thut in T - HBK Chapter 7 - p2 34

17
8/9/2016

SPIOperation
Totransferdata,themasterselectsaslavedeviceto
talkto,bytakingitsSSlinelow.
Eightdatabitsarethenclockedinoroutoftheslave
SPIshiftregistertoorfromthemaster.Nostartand
stopbitsarenecessary,anditismuchfasterthan
RS232.
Theclocksignalrunsatthesamespeedasthemaster
instructionclock,thatis,5MHzwhenthechipis
runningatthemaximum20MHz(16seriesMCUs).

B mn K Thut in T - HBK Chapter 7 - p2 35

SPIDriverFunctions

B mn K Thut in T - HBK Chapter 7 - p2 36

18
8/9/2016

SPITest
System
Schematic

B mn K Thut in T - HBK Chapter 7 - p2 37

Masterandslavessourcecode

B mn K Thut in T - HBK Chapter 7 - p2 38

19
8/9/2016

Outline

1.PIC16UARTSerialLink
2.PIC16SPISerialBus
3.I2CSerialBus

B mn K Thut in T - HBK Chapter 7 - p2 39

I2CBus
Theinterintegratedcircuit(I2C)busisdesignedfor
shortrangecommunicationbetweenchipsinthesame
systemusingasoftwareaddressingsystem.
Itrequiresonlytwosignalwiresandoperateslikea
simplifiedlocalareanetwork.

I2C connection

I2C signals

B mn K Thut in T - HBK Chapter 7 - p2 40

20
8/9/2016

I2CBus
TheI2Cslavechipsareattachedtoatwowire
bus,whichispulleduptologic1whenidle.
Passiveslavedeviceshavetheirregisteror
locationaddressesdeterminedbyacombination
ofexternalinputaddresscodepinsandfixed
internaldecoding.
AsforSPI,theclockisderivedfromthe
instructionclock,upto5MHzatthemaximum
clockrateof20MHz.

B mn K Thut in T - HBK Chapter 7 - p2 41

I2CBus
Tosendadatabyte,themasterfirstsendsacontrolcodetoset
upthetransfer,thenthe8bitor10bitaddresscode,andfinally
thedata.Eachbytehasastartandacknowledgebit,andeach
bytemustbeacknowledgedbeforethenextissent,toimprove
reliability.
Thesequencetoreadasinglebyterequiresatotalof5bytesto
completetheprocess,3tosettheaddress,and2toreturnthe
data

B mn K Thut in T - HBK Chapter 7 - p2 42

21
8/9/2016

I2CFunctions

B mn K Thut in T - HBK Chapter 7 - p2 43

I2CTestSystem
DSW1
ON OFF +5V
13 33 1 9
OSC1/CLKIN RB0/INT
14 34 2
OSC2/CLKOUT RB1
1 35 3
MCLR/Vpp/THV RB2
36 4
RB3/PGM
2 37 5
RA0/AN0 RB4
3 38 6
RA1/AN1 RB5
4 39 7
RA2/AN2/VREF- RB6/PGC
5
RA3/AN3/VREF+ RB7/PGD
40 8 R1 R2
6 4k7 4k7
RA4/T0CKI
7 15 DIPSWC_8
RA5/AN4/SS RC0/T1OSO/T1CKI
16
8
RC1/T1OSI/CCP2
17 U2
RE0/AN5/RD RC2/CCP1
9 18 6 1
RE1/AN6/WR RC3/SCK/SCL SCK A0
10 23 5 2
RE2/AN7/CS RC4/SDI/SDA SDA A1
24 7 3
RC5/SDO WP A2
25
RC6/TX/CK
26 24FC256
RC7/RX/DT
19
RD0/PSP0
20
RD1/PSP1
21
RD2/PSP2 SDA
22
RD3/PSP3
RD4/PSP4
RD5/PSP5
27
28
29
SCL I2C
RD6/PSP6 TRIG
30
RD7/PSP7
PIC16F877A
U1

B mn K Thut in T - HBK Chapter 7 - p2 44

22
8/9/2016

I2CTestSystem

B mn K Thut in T - HBK Chapter 7 - p2 45

23

You might also like