Text preview for : Clavier.pdf part of MAAS KNT-5000 Stabilized DC Power Supply
MAAS KNT-5000
Back to : Maas KNT-5000.pdf | Home
M
Author:
AN552
SUMMARY
The PIC16CXXX is ideally suited to interface directly to a keypad application. Built in pull-up resistors and very low current consumption during sleep make it a very good candidate for battery powered remote operations and applications. Appendix A provides an example of the code. Performance: Code Size RAM Used 64 words 0 bytes
Implementing Wake-up on Key Stroke
Stan D'Souza Microchip Technology Inc.
INTRODUCTION
Microchip's PIC16CXXX microcontroller family are ideally suited to directly interface to a keypad. The high 4-bits of PORTB (RB7:RB4) have internal pull-ups and can trigger a "change on state" interrupt. This interrupt, if enabled, will wake the microcontroller from SLEEP. In most battery powered applications, a microcontroller is exercised when a key is pressed (e.g., in a remote keyless entry system). The life of the battery can be extended by using PIC16CXXX microcontrollers. This is done by putting the PIC16CXXX microcontroller into SLEEP mode for most of the time and wake-up only when a key is pressed.
FIGURE 1:
4 KEY INTERFACE TO PIC16CXXX
4x1k LED1 LED2 LED3 LED4 SW1 SW2 SW3 SW4 4x100
RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 PIC16CXXX
IMPLEMENTATION
Figure 1 depicts an application where four keys are connected to RB7:RB4. Internal pull-ups are used to maintain a high level on these inputs. In this example, LEDs are connected to RB3:RB0. When SW1 is pressed, LED1 is turned on and when SW2 is pressed, LED2 is turned on and so on. The PIC16CXXX is normally in SLEEP mode with the "change on state" interrupt enabled. When SW1 is pressed, RB4 goes low and triggers an interrupt. Since the PIC16CXXX is in SLEEP, it first wakes up and starts executing code at the interrupt vector. Note that if the global interrupt is enabled, the program execution after an interrupt is at the interrupt vector, if the global interrupt is not enabled, the program starts executing the first line of code right after the SLEEP instruction. After waking up, a 20 - 40 ms de-bounce delay is executed which checks the port for a key hit and, depending on which key is hit, its associated LED is turned on. The LEDs are used purely for demonstration purposes. In a remote keyless entry application, the remote code would be transmitted when the appropriate key is hit. Figure 2 depicts a 4x4 keypad interface to a PIC16CXXX microcontroller. When using the PIC16CXXX in a keypad application, the internal pull-ups on RB7:RB4 can be enabled, eliminating the need for external pull-up resistors. The series 100 resistors are used for Electrostatic Discharge (ESD) protection, and are recommended in keypad interface applications.
4x4 Key Matrix
FIGURE 2:
4x4 KEYPAD INTERFACE TO PIC16CXXX
RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7
8x100
PIC16CXXX
© 1997 Microchip Technology Inc.
DS00552E-page 1
AN552
Please check the Microchip BBS for the latest version of the source code. Microchip's Worldwide Web Address: www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required).
APPENDIX A : WAKUP.ASM
MPASM 01.40 Released WAKUP.ASM 1-16-1997 16:04:19 PAGE 1
LOC OBJECT CODE VALUE
LINE SOURCE TEXT
00000002 00000007 00000010 00000001 00000001
0000 0000 2805 0004 0004 2808
0005 0005 2024 0006 0006 0000 0007 2806 0008 0008 0009 000A 000B 000C
180B 280D 128B 110B 0008
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00001 00002 00142 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051
;This program demonstrates the wake-up on Keystroke feature of ;the PIC16C71. Port B pins RB4 - RB7 can be configured as inputs with ;internal pull up resistors, also the interrupt associated with the ;change on input on RB4 - RB7 can be set up to wake the chip from ;sleep. If the global interrupt is enabled just before sleep, the ;program will vector to the interrupt vector (0004). If not, the chip ;will continue execution just after the next instruction following ;sleep. In this example code, port B is initialized to input 4 ;push-buttons at RB4 - RB7. RB0 - RB3 are configured to drive LEDs ;corresponding to which pushbutton is hit (LED on RB0 when RB4 is ;hit and so on). Sleep is executed. When any key is hit, the ;processor wakes up and jumps to the interrupt vector. The ;corresponding LED is turned on and after the key is released, the ;whole process is repeated. ; ; Program: WAKEUP.ASM ; Revision Date: ; 1-16-97 Compatibility with MPASMWIN 1.40 ; ;************************************************************************ ; LIST P=16C71 ; z equ 2 RBPU equ 7 temp equ 10h OptionReg equ 1h F EQU 1 ; include "p16c71.inc" LIST ;P16C71.INC Standard Header File, Version 1.00 Microchip Technology LIST ; org 0 goto start ; org 4 goto ServiceInterrupt ; ; start call InitPortB ;initialize port B loop sleep ;sleep till key is hit nop goto loop ; ServiceInterrupt btfsc INTCON,RBIF ;change on rb int? goto ServiceWakup ;yes then service bcf INTCON,T0IE ;clear TMR0 int mask bcf INTCON,T0IF ;clear flag return
DS00552E-page 2
© 1997 Microchip Technology Inc.
AN552
00052 00053 00054 00055 00056 000D 00057 000D 118B 00058 000E 0906 00059 000F 100B 00060 0010 2035 00061 0011 0906 00062 0012 39F0 00063 0013 0090 00064 0014 0E10 00065 0015 0086 00066 0016 2018 00067 0017 0009 00068 00069 00070 00071 00072 0018 00073 0018 2035 00074 0019 0906 00075 001A 100B 00076 001B 158B 00077 001C 39F0 00078 001D 1903 00079 001E 0008 00080 001F 0063 00081 0020 118B 00082 0021 0906 00083 0022 100B 00084 0023 2818 00085 00086 00087 00088 0024 00089 0024 1683 00090 0025 3003 00091 Message[302]: Register in 0026 0088 00092 0027 3000 00093 0028 0085 00094 0029 30F0 00095 002A 0086 00096 002B 1381 00097 002C 1283 00098 002D 0186 00099 002E 0185 00100 002F 1405 00101 0030 118B 00102 0031 0806 00103 0032 100B 00104 0033 158B 00105 0034 0009 00106 00107 00108 00109 0035 00110 0035 1683 00111 0036 3007 00112 0037 0081 00113 0038 1283 00114 0039 0181 00115 003A 110B 00116 ; ;This routine checks which key is hit and lights up the ;corresponding LED associated with it. eg. RB0's LED when ;RB4's key is pressed. Finally it waits till all keys have ;been released before returning form the service routine. ServiceWakup bcf INTCON,RBIE ;clear mask comf PORTB,W ;read PORTB bcf INTCON,RBIF ;clear flag call delay16 ;do de-bounce for 16mSecs comf PORTB,W ;read port B again andlw B'11110000' ;mask outputs movwf temp ;save in temp swapf temp,W ;switch low and high movwf PORTB ;send as outputs. call KeyRelease ;check for key release retfie ; ;This sub-routine, waits till all key have been released ;In order to save power, the chip is in sleep mode till ;all keys are released. KeyRelease call delay16 ;do debounce comf PORTB,W ;read PORTB bcf INTCON,RBIF ;clear flag bsf INTCON,RBIE ;enable mask andlw B'11110000' ;clear outputs btfsc STATUS,z ;key still pressed? return ;no then return sleep ;else save power bcf INTCON,RBIE ;on wake up clear mask comf PORTB,W bcf INTCON,RBIF ;clear flag goto KeyRelease ;try again ; ; ;This sub-routine, initializes PortB. InitPortB bsf STATUS,RP0 ;select bank1 movlw B'00000011' ;Port_A digital I/O operand not in bank 0. Ensure that bank bits are correct. movwf ADCON1 ; / movlw 0 ; movwf PORTA ;set port a as outputs movlw B'11110000' ;RB0-RB3 outputs movwf PORTB ;RB4-RB7 inputs bcf OptionReg,RBPU ;enable pull up bcf STATUS,RP0 ;select page 0 clrf PORTB ;init port B clrf PORTA ;make port a all low bsf PORTA,0 ;make first bit high bcf INTCON,RBIE ;disable mask movf PORTB,W ;read port bcf INTCON,RBIF ;clear flag bsf INTCON,RBIE ;enable mask retfie ;enable global and return ; ;delay16 waits for approx 16.4mSecs using TMR0 interrupts ;fosc speed is 4Mhz. delay16 bsf STATUS,RP0 ;select Bank1 movlw B'00000111' ;fosc/256 --> TMR0 movwf OptionReg ; / bcf STATUS,RP0 ;select Bank0 clrf TMR0 bcf INTCON,T0IF ;clear flag
© 1997 Microchip Technology Inc.
DS00552E-page 3
AN552
003B 003C 003C 003D 003E 003F 0040 00117 bsf INTCON,T0IE 00118 CheckAgain 1D0B 00119 btfss INTCON,T0IF 283C 00120 goto CheckAgain 128B 00121 bcf INTCON,T0IE 110B 00122 bcf INTCON,T0IF 0008 00123 return 00124 ; 00125 end MEMORY USAGE MAP ('X' = Used, '-' = Unused) 168B ;enable mask ;timer overflowed? ;no check again ;else clear mask ;clear flag
0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : X--------------- ---------------- ---------------- ---------------All other memory blocks unused. Program Memory Words Used: Program Memory Words Free: 62 962
Errors : Warnings : Messages :
0 0 reported, 1 reported,
0 suppressed 0 suppressed
DS00552E-page 4
© 1997 Microchip Technology Inc.
WORLDWIDE SALES & SERVICE
AMERICAS
Corporate Office
Microchip Technology Inc. 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 602-786-7200 Fax: 602-786-7277 Technical Support: 602 786-7627 Web: http://www.microchip.com
ASIA/PACIFIC
Hong Kong
Microchip Asia Pacific RM 3801B, Tower Two Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2-401-1200 Fax: 852-2-401-3431
EUROPE
United Kingdom
Arizona Microchip Technology Ltd. Unit 6, The Courtyard Meadow Bank, Furlong Road Bourne End, Buckinghamshire SL8 5AJ Tel: 44-1628-851077 Fax: 44-1628-850259
France
Arizona Microchip Technology SARL Zone Industrielle de la Bonde 2 Rue du Buisson aux Fraises 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79
Atlanta
Microchip Technology Inc. 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307
India
Microchip Technology India No. 6, Legacy, Convent Road Bangalore 560 025, India Tel: 91-80-229-0061 Fax: 91-80-229-0062
Boston
Microchip Technology Inc. 5 Mount Royal Avenue Marlborough, MA 01752 Tel: 508-480-9990 Fax: 508-480-8575
Korea
Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea Tel: 82-2-554-7200 Fax: 82-2-558-5934
Germany
Arizona Microchip Technology GmbH Gustav-Heinemann-Ring 125 D-81739 Müchen, Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
Chicago
Microchip Technology Inc. 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075
Italy
Arizona Microchip Technology SRL Centro Direzionale Colleone Palazzo Taurus 1 V. Le Colleoni 1 20041 Agrate Brianza Milan, Italy Tel: 39-39-6899939 Fax: 39-39-6899883
Shanghai
Microchip Technology RM 406 Shanghai Golden Bridge Bldg. 2077 Yan'an Road West, Hongiao District Shanghai, PRC 200335 Tel: 86-21-6275-5700 Fax: 86 21-6275-5060
Dallas
Microchip Technology Inc. 14651 Dallas Parkway, Suite 816 Dallas, TX 75240-8809 Tel: 972-991-7177 Fax: 972-991-8588
Singapore
Microchip Technology Taiwan Singapore Branch 200 Middle Road #10-03 Prime Centre Singapore 188980 Tel: 65-334-8870 Fax: 65-334-8850
JAPAN
Microchip Technology Intl. Inc. Benex S-1 6F 3-18-20, Shin Yokohama Kohoku-Ku, Yokohama Kanagawa 222 Japan Tel: 81-4-5471- 6166 Fax: 81-4-5471-6122 5/8/97
Dayton
Microchip Technology Inc. Two Prestige Place, Suite 150 Miamisburg, OH 45342 Tel: 937-291-1654 Fax: 937-291-9175
Los Angeles
Microchip Technology Inc. 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 714-263-1888 Fax: 714-263-1338
Taiwan, R.O.C
Microchip Technology Taiwan 10F-1C 207 Tung Hua North Road Taipei, Taiwan, ROC Tel: 886 2-717-7175 Fax: 886-2-545-0139
New York
Microchip Technology Inc. 150 Motor Parkway, Suite 416 Hauppauge, NY 11788 Tel: 516-273-5305 Fax: 516-273-5335
San Jose
Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955
Toronto
Microchip Technology Inc. 5925 Airport Road, Suite 200 Mississauga, Ontario L4V 1W1, Canada Tel: 905-405-6279 Fax: 905-405-6253
All rights reserved. © 1997, Microchip Technology Incorporated, USA. 6/97
Information contained in this publication regarding device applications and the like is intended for suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip's products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. The Microchip logo and name are registered trademarks of Microchip Technology Inc. in the U.S.A. and other countries. All rights reserved. All other trademarks mentioned herein are the property of their respective companies.
M
© 1997 Microchip Technology Inc.
DS00552E-page 5