Upload
vudiepdh1
View
37
Download
2
Embed Size (px)
Citation preview
Pushbuttons
Pushbuttons in Real Life
� Computer
� Mouse
� Calculator
� Microwave oven
� Handheld remote
� Handheld games
� VCR
Testing a Pushbutton with an
LED Circuit
Pushbutton Test Circuit
A Short-Circuit
The 4x4 Keypad
The 4×4 Keypad Block
C2R1
R303
10k
SW9
SW2
SW12
C0
SW3
SW11SW10
SW7
R2
R2
C3
3.KEYPAD 4*4
SW8
C1
J301
2 4 6 8 10
12
14
16
1 3 5 7 9 11
13
15
R1
SW6
SW11 3
2 4
C0
SW14
R301
10k
R0
SW16
SW4
R0
SW13
C2
C1
R304
10k
R302
10k
VCC
R3
SW5
SW15
C3
R3
Testing the 4×4 Keypad
� Try to connect the Keypad jumpers R0-R3 to
the LED array to make sure that there is a
current goes through them
Example:
Reading a Pushbutton
Problem Description
� Develop a program to check the pushbutton
(R0, C0). If it is pressed, light up a LED. Turn
off the LED if the button is released
Schem
atic
C1
SW
3
C101
20pF
D207
SW
15
R3
D203
J301
246810121416
13579111315
VC
C
R1
D205
D206
R301
10k
R304
10k
R203
330
SW
2
SW
5
C3
D204
R0
SW
9
SW
14
R205
330
R208
330
C102
20pF
R302
10k
PIC16F877A
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
VSS
VDD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
U101
1
234567
8910
11
12
1314
15161718
19202122
23242526
27282930
31
32
3334353637383940
C0
1.PIC BLOCK
SW
8
R201
330
2.LED BLOCK
R101
100
R207
330
D202
C2
SW
11
3
24
R2
C2
SW
6
SW
11
SW
4
SW
7
C1
SW
16
D201J201
910111213141516
12345678
R1
C3
SW
10
VC
C
R3
SW
12
C0
D208
R2
R303
10k
SW
13
R204
330
SW
7
3.KEYPAD 4*4
R202
330
R0
R206
330
Y101
4M
Cable Wiring
B0B1
C0
R0
GND
Example: Two Pushbuttons
Controlling Two LEDs
Problem Description
� Develop a program to make 2 pushbuttons
controlling two different LEDs. For example,
� If button (R0, C0) is pressed, light up LED0. When (R0, C0) is released, turn off LED0
� If button (R1, C0) is pressed, light up LED1. When (R1, C0) is released, turn off LED1
Cable Wiring
B0-B1
A1-A2
C0
R0-R1
GND
L0-L1
Interesting Exercise
� Try to press the two buttons at once. What do
you see?
� Modify the program so that if both buttons are
pressed, both LEDs are to be on
� Present your solution to the class
� Can your program handle well the following situation: The first button is pressed, this button is still kept pressed, then the second button is
pressed
Solution
Example:
Displaying Key Code
Problem Description
� Develop a program to display the key code
to the LED array when a button is pressed
Electro
nic S
chem
a
R205
330
R2
SW
6
R2
C3
D204
R206
330
C0
SW
14
SW
4
R0
R201
330
J301
246810121416
13579111315
SW
11
SW
16
3.KEYPAD 4*4
R3
D208
D202
SW
11
3
24
VC
C
SW
7
Y101
4M
VC
C
C1
R101
100
SW
8
J201
910111213141516
12345678
R1
SW
13
SW
10
C3
PIC16F877A
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
VSS
VDD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
U101
1
234567
8910
11
12
1314
15161718
19202122
23242526
27282930
31
32
3334353637383940
C102
20pF
R0
R208
330
D203
C2
R304
10k
SW
3
R203
330
C2
SW
7
1.PIC BLOCK
D205
C1
R1
R204
330
SW
12
C101
20pF
SW
15
SW
5
R207
330
D207
D201
D206
R3
R303
10k
SW
2
2.LED BLOCK
R202
330
R301
10kS
W9
R302
10k
C0
Exercise
� Observe the LEDs while running the program
Exercise
� Develop a program to control the blink of
eight LEDs. The blinking pattern can be
changed with 4 pushbuttons
� Pattern 0:
� Pattern 1:
� Pattern 2:
� Pattern 3:
Example: Displaying Key
Pressed on LCD
Problem Description� Develop a program to echo a 4x4 keypad
entry to the LCD display. All keys are echoed
except * that will clear the display
Electro
nic S
chem
a
C2
Y101
4M
R1
R303
10k
SW
9
SW
2
SW
12
C0
SW
3
SW
11
VSS
VDD
V0
RS
R/W
EAK
B0
B1
B2
B3
B4
B5
B6
B7 U
1
LC
D
1 2
3456
78910
11
12
13
14
15
16
SW
10
SW
7
R2
R2
C101
20pF
1.PIC BLOCK
C3
R1
RE
SIS
TO
R V
AR
R101
100
3.KEYPAD 4*4
VC
C
SW
7
SW
8
C1
J301
246810121416
13579111315
R1
VC
C
SW
6
SW
11
3
24
C0
SW
14
R301
10k
C102
20pF
R0
SW
16
SW
4
R0
SW
13
C2
C1
R304
10k
R302
10k
VC
C
PIC16F877A
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
VSS
VDD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
U101
1
234567
8910
11
12
1314
15161718
19202122
23242526
27282930
31
32
3334353637383940
R3
SW
5
SW
15
C3
R3
Example: Displaying Numeric
Key on 7-Segment LED
Problem Description
� Develop a program to echo digit-key presses
(0 to 9) of a 4x4 keypad to the 7-segment
LED
Electronic Schema
C102
20pF
A
U605
A B C D E F G H
VC
C
VC
C
R0
R601100
C0
Q602A1015
31
2R614
1k
R302
10k
D
R101
100
R612
1k
SW7
Q605 A1015
31
2
R608100
SW7
SW2
Q604 A1015
31
2
J301
2 4 6 8 10
12
14
16
1 3 5 7 9 11
13
15
E
SW4SW11 3
2 4
R1
SW3
C2
H
R1
R602100
SW6
R301
10k
R607100
C2
R0
C0
SW10
R6091k
VCC
U604
A B C D E F G H
VC
C
VC
C
SW8
C3
C1
SW9
PIC16F877A
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
VSS
VDD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
U101
1
234567
89
10
11
12
1314
15161718
19202122
23242526
27282930
31
32
3334353637383940
C5
SW11
R6131k
SW14
C3
SW12
C3
6.LED 7_SEGMENT BLOCK
R603100
R3
R6111k
U606
A B C D E F G H
VC
C
VC
C
J602
HEADER 8X2
2 4 6 8 10
12
14
16
1 3 5 7 9 11
13
15
C101
20pF
U601
A B C D E F G H
VC
C
VC
C
3.KEYPAD 4*4
R605100
G
R3
R606100
Q601A1015
31
2
VCC
R2
C4
U603
A B C D E F G H
VC
C
VC
C
U602
A B C D E F G H
VC
C
VC
C
F
SW16
R604100
SW5
C1
R610
1k
1.PIC BLOCK
SW13
R2 C0
C
VCC
C1
VCC
C2
SW15
B
J601
HEADER 6X22 4 6 8 10
12
1 3 5 7 9 11
Y101
4M
Q606
A1015
31
2Q603
A1015
31
2
R304
10k
R303
10k
Switch Bounce
Switch Bounce� When a pushbutton is pressed or released it is not usually a simple on-off
contact
� The contact usually bounces on and off a number of times before settling down
How Long does It Take?
� How long this takes depends on the
construction of the switch, but 10
milliseconds is usually long enough unless
the switch is really poor
� We must also be concerned with bounce on
release
References
� What's a Microcontroller Student Guide v 2.2.
Parallax 2004
� PICC\Examples\EX_LCDKB.c
� PIC Circuits Gallery LED flasher.
http://www.interq.or.jp/japan/se-
inoue/e_pic6_1.htm
� Counting Presses of a Button.
http://www.piclist.com/techref/piclist/cheapic/s
wcnt.htm