Sie sind auf Seite 1von 40

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

VCC

The 44 Keypad Block


C0
SW1

C1
SW2 3 4 SW3

C2
SW4

C3 R0

R304R303R302R301 1 10k 10k 10k 10k 2

SW5

SW6

SW7

SW8

R1
SW9 SW10 SW11 SW12

R2
SW13 SW14 SW15 SW16

R3

1 3 5 7 9 11 13 15

J301 R3R2R1R0C3C2C1C0

3.KEYPAD 4*4

2 4 6 8 10 12 14 16

Testing the 44 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

10k 10k 10k 10k

R304R303R302R301 1

VCC

Schematic

SW9

SW13

SW5

SW1

C0

R3R2R1R0C3C2C1C0 J301

2 4 6 8 10 12 14 16

1 3 5 7 9 11 13 15

SW14

SW10

SW6

SW2

C1

3.KEYPAD 4*4
1.PIC BLOCK 2.LED BLOCK

SW15 SW16

SW7

SW3

SW11 SW12

C2

SW8

SW4

C3

R2

R1

2 3 4 5 6 7 8 9 10

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

R3
32 VDD

R0

VDD RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT 33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30

11

VCC R101 100 Y101 4M C101 20pF 9 10 11 12 13 14 15 16

SW7 C102 20pF

1 13 14

MCLR/VPP OSC1/CLKI OSC2/CLKO

PIC16F877A

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7

VSS U101 1 2 3 4 5 6 7 8 J201 12

VSS 31 D208 D207 D206 D205 D204 D203 D202 D201 R208 R207 R206 R205 R204 R203 R202 R201 330 330 330 330 330 330 330 330

Cable Wiring

B1

B0

R0 C0

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
L0-L1

B0-B1

A1-A2 R0-R1 C0 GND

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

10k 10k 10k 10k

R304R303R302R301 1

VCC

Electronic Schema

SW9

SW13

SW5

SW1

C0

R3R2R1R0C3C2C1C0 J301

2 4 6 8 10 12 14 16

1 3 5 7 9 11 13 15

SW14

SW10

SW6

SW2

C1

3.KEYPAD 4*4
1.PIC BLOCK 2.LED BLOCK

SW15 SW16 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

SW7

SW3

SW11 SW12

C2

SW8

SW4

C3

R1

R0

R3
32 VDD 2 3 4 5 6 7 8 9 10

R2
VDD 11

RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT

33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30

VCC R101 100 Y101 4M C101 20pF 9 10 11 12 13 14 15 16

SW7 C102 20pF

1 13 14

MCLR/VPP OSC1/CLKI OSC2/CLKO

PIC16F877A

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7

VSS U101 1 2 3 4 5 6 7 8 J201 12

VSS 31 D208 D207 D206 D205 D204 D203 D202 D201 R208 R207 R206 R205 R204 R203 R202 R201 330 330 330 330 330 330 330 330

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

10k 10k 10k 10k

R304R303R302R301 1

VCC

Electronic Schema

SW9

SW13

SW5

SW1

C0

R3R2R1R0C3C2C1C0 J301

2 4 6 8 10 12 14 16

1 3 5 7 9 11 13 15

SW14

SW10

SW6

SW2

C1

3.KEYPAD 4*4
1.PIC BLOCK

SW15 SW16

SW7

SW3

SW11 SW12

C2

SW8

SW4

C3

2 3 4 5 6 7 8 9 10

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

R3
VDD

R2
32 VDD 11

R1
RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT

33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30

R0

VCC R101 100 Y101 4M C101 20pF

SW7 C102 20pF

1 13 14

MCLR/VPP OSC1/CLKI OSC2/CLKO

PIC16F877A

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7

VSS U101 1 12

VSS 31 7 B0 8 B1 9 B2 10 B3 11 B4 12 B5 13 B6 14 B7 U1

LCD

VSS

VDD V0

A K 15 16

RS R/W E 4 5 6

3 RESISTOR VAR VCC R1

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
VCC 1 VCC 1 Q605 A1015 2 1k 3 U604 VCC VCC VCC U605 VCC VCC R612 1 Q606 R613 1k U606 VCC VCC 3 32 11 Q601 A1015 2 1k 3 RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT 33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 A B C D E F G H A B C D E F G H A B C D E F G H A B C D E F G H A B C D E F G H 19 20 21 22 27 28 29 30 A B C D E F G H R609 1k U602 VCC VCC VCC 3 U603 VCC 3 VDD VCC R101 100 2 3 4 5 6 7 8 9 10 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 Q602 A1015 2 R610 Q603 A1015 2 1k R611 3 Q604 A1015 2 1k 1 1 1 A1015 2 R614 U601 VCC SW7 C102 1 13 14 Y101 4M MCLR/VPP OSC1/CLKI OSC2/CLKO

C101 20pF

20pF

PIC16F877A

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7

VSS 12

VSS 31 U101 R601 R604 R607 R602 R605 R608 R603 R606 100 100 100 100 100 100 100 100

1.PIC BLOCK

6.LED 7_SEGMENT BLOCK


J601 VCC

1 3 5 7 9 11 13 15

J602 HEADER 8X2 A B C D E F G H 2 4 6 8 10 12 14 16 2 4 6 8 10 12 C0C1C2C3C4C5

1 3 5 7 9 11

C0
HEADER 6X2 R304 R303 R302 R301 1 10k 10k 10k 10k 2 SW1 3 4

C1
SW2 SW3

C2
SW4

C3
SW5 SW6 SW7 SW8

R0
SW9 SW10 SW11 SW12

R1
SW13 SW14 SW15 SW16

R2

1 3 5 7 9 11 13 15

R3
J301

R3R2R1R0C3C2C1C0

3.KEYPAD 4*4

2 4 6 8 10 12 14 16

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/seinoue/e_pic6_1.htm Counting Presses of a Button. http://www.piclist.com/techref/piclist/cheapic/s wcnt.htm

Das könnte Ihnen auch gefallen