Interfacing Between The Psoc and The World
Interfacing Between The Psoc and The World
GPIO - 1
Microcontroller System Design
GPIO
General Purpose I/O refers to using individual port
pins under program control
Output CPU can set a pin high or low at any time
Input CPU can read the value on a pin at any time
Example: To output a square wave on port2[0]
Set port2[0] low
Pause
Set port2[0] high
Pause
Repeat
GPIO - 2
Microcontroller System Design
GPIO Ports
The PSoC has up to eight
eight-bit ports
29466 has three ports
Port0 Port2
29566 has five ports
Port0 Port4
29666 has six ports
Port0 Port5
29866 has eight ports
Port0 Port7
GPIO - 3
Microcontroller System Design
29466 Ports
Three ports
All can be used for digital I/O
Ports 0 and 2 have some
capacity for analog I/O
Many pins have constraints
for special-purpose use
See Part-# Datasheet for
details
GPIO - 4
Microcontroller System Design
GPIO Configuration
The first step is to configure the port pins
Basic output mode called Strong Drive
Basic input mode called Hi-Z
Port pins may be configured individually, with mixed
GPIO - 5
Microcontroller System Design
Default is High-Z
Analog (input)
StdCPU means port
read/written by CPU
GPIO - 6
Microcontroller System Design
GPIO - 7
Microcontroller System Design
GPIO - 8
Microcontroller System Design
bank is selected
REG[0] = PRT0DR in bank 0, PRT0DM0 in bank 1
Bank selection is made with the XIO bit in the FLAG register
Bit 4 of Flag Register = XIO = Current Register Bank
Select Reg Bank 0: AND F, %11101111
MOV REG[PRT1DM2], %11011011
Macro M8C_SetBank0
M8C_SetBank1 // set Bank 1
Select Reg Bank 1: OR F, %00010000 MOV REG[PRT1DM1], %11111011
MOV REG[PRT1DM0], %00000100
Macro M8C_SetBank1
M8C_SetBank0 // set Bank 0
Convention Normally in Bank 0
If change to Bank 1, must change back to Bank 0 when done
GPIO - 9
Microcontroller System Design
Register References
All registers are described in TRM section C-13
Bank zero register addresses listed as 0,xxh
0,01h Bank 0, REG[01] (PRT0IE)
Bank one registers addresses listed as 1,xxh
1,03h Bank 1, REG[03] (PRT0IC1)
Also, look at m8c.inc in External Headers of
Application Editor in PSoC Designer
Browse around this file a bit to find useful macros
GPIO - 10
Microcontroller System Design
4
1
1
0
3
1
1
0
1
1
1
0
0
1
1
0
=H
i-Z
i-Z
g
alo
An
g
alo
An
fau
( de
lt)
lt)
t)
lt)
lt)
lt)
lt)
tpu
fau
( de
(ou
fau
( de
rive
g
alo
An
t)
fau
( de
pu
fau
( de
fau
( de
l in
g
alo
An
a
git
(di
g
alo
An
g
alo
An
D
ng
i-Z
i-Z
i-Z
i-Z
i-Z
tro
=H
=S
=H
=H
=H
=H
=H
2
0
0
1
6
DM
6
DM
6
DM
2
DM
6
DM
6
DM
Bank1
6
1
1
0
6
DM
7
PRT1DM2 1
PRT1DM1 1
PRT1DM0 0
1
DM
Bank 0
M8C_SetBank0
MOV REG[PRT1DM2], %11011011
M8C_SetBank1
MOV REG[PRT1DM1], %11111011
MOV REG[PRT1DM0], %00000100
M8C_SetBank0
GPIO - 11
Microcontroller System Design
Bi-Directional Ports
MACRO Port3Output
M8C_SetBank0
MOV REG[PRT3DM2], %00000000
M8C_SetBank1
MOV REG[PRT3DM1], %00000000
MOV REG[PRT3DM0], %11111111
M8C_SetBank0
ENDM
GPIO - 12
Microcontroller System Design
VCC
To PSoC
Input Logic
To PSoC
Input Logic
Port Pin
Port Pin
From
PSoC
Core
From
PSoC
Core
GND
GND
Slow Strong Drive Mode
GPIO - 13
Microcontroller System Design
VCC
To PSoC
Digital Input Logic
To PSoC
Analog Input Logic
Port Pin
GND
Hi-Z Mode
Digital Input Mode
Port Pin
GND
Analog Hi-Z Mode
Analog Input Mode.
Select when port is unused
since it consumes no power.
GPIO - 14
Microcontroller System Design
5.6K
VCC
To PSoC
Input Logic
To PSoC
Input Logic
Port Pin
Port Pin
From
PSoC
Core
5.6K
GND
From
PSoC
Core
Resistive Pull-Up
GND
Resistive Pull-Down
Effective Circuit if written with 0
VCC
5.6K
To PSoC
Input Logic
Port Pin
WARNING:
If you are using this
mode as input-only,
make sure to write
correct value to port!
To PSoC
Input Logic
Port Pin
5.6K
GPIO - 15
Microcontroller System Design
SPST Button:
Produces either Vcc
or Floating input.
Button
VCC
To PSoC
Input Logic
Button
Port Pin
5.6K
Adding a pull-down
resistor fixes it.
5.6K
PSoC port in
Pull-Down mode
Dont Forget:
Write 0 to port
GPIO - 16
Microcontroller System Design
GPIO - 17
Microcontroller System Design
Inc
COUNT
Display
COUNT
Poll
for 1
Displays 1
Inc
COUNT
Display
COUNT
Poll
for 1
Displays 2
GPIO - 19
Microcontroller System Design
Bouncing Switches
VCC
time
Button
Pressed
Released
GPIO - 20
Microcontroller System Design
5.6K
De-bouncing
De-bouncing switches is critical to most systems
Solutions may involve hardware changes or
software changes
Hardware:
Build hardware that gets rid of the bounce
Works well, but costs $$$, space and power
Software:
Write software to ignore bounces
Cheap, but harder to fine-tune
GPIO - 21
Microcontroller System Design
Pushbutton
Single-Pole Double-Throw (SPDT) Switch
Input
+5
GND
GND
De-Bounced
Output
S
GPIO - 22
Microcontroller System Design
De-Bounced
VCC
Button
rise time
Can also view as filtering out highfrequency response
Requires a carefully-sized capacitor,
matched with the resistor ($)
Slows down response time
GPIO - 23
Microcontroller System Design
Software De-Bounce
Whenever a change in the input value is detected, ignore the
input for some period of time afterward
Example: Delay 25ms after input changes
25ms
25ms
GPIO - 24
Microcontroller System Design
GPIO - 25
Microcontroller System Design
MOV A, 255
NOP
NOP
DEC A
JNZ DELAY
RET
Problems
Time delay depends on clock speed may change
Time delay depends on CPI may change
Icky to compute just how long delay is
GPIO - 26
Microcontroller System Design
GPIO - 27
Microcontroller System Design
; Turn on interrupts
; Start SleepTimer
; Use 512 Hz interrupt rate
mov A,13
lcall SleepTimer_TickWait
; Put main loop user code here
jmp Loop
Loop:
GPIO - 28
Microcontroller System Design