Virtual Integrated Design

Keypad Circuit

 



Main File:


/*
keypad.c
Compiler: Hitech
Device: Pic16F84
Oscillator Freq: 4Mhz
Baud Rate: 9600
www.viddata.com

This project adds a 4x4 keypad to a larger project that needs
more user input than a couple switches.
When a key is pressed the 16F84 micro detects it and transmits
the ascii character for that key on a 1 wire rs232 interface.
The 10us delay helps check for a valid keypress and the 2-200ms
delays are to debounce the keys.

Copyright 2002, Virtual Integrated Design, all rights reserved.
*/

#include <pic.h>
#include "09f14m4.h"
#include "delay.h"

#define INPUT 1
#define OUTPUT 0

void main()
{

    const unsigned char keypad[]= {0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88};
    const unsigned char character[] = {'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
    unsigned char i,ii;

    TRISA1=OUTPUT;
    TRISA3=OUTPUT;
    TRISB=0xF0;
    RA1=1;
    RA3=1;
    __CONFIG(UNPROTECT|1); /* xtal, no protect */

    while(1)
    {
        PORTB=0x0F; /* init/re-init port */
        while(PORTB==0x0F); /* wait for key press */
        DelayUs(10);
        if(PORTB!=0x0F)
        {
            for(i=0;i<4;i++)
            {
                PORTB=1<<i;
                for(ii=0;ii<16;ii++)
                {
                    if(PORTB==keypad[ii])
                    { 
                        RA3=0; /* led */
                        DelayMs(200);
                        DelayMs(200);
                        RA3=1;
                        transmit_9600_RA1(character[ii]);
                        i=4;
                        break; 
                    }
                }
            } 
        }
    }
}

Hex File:

:10000000830100308A0004288301BA2B820711344F
:100010002134413481341234223442348234143451
:1000200024344434843418342834483488348207DF
:100030003134323433344134343435343634423468
:1000400037343834393443342A3430342334443464
:100704008F000430900053309100910B872B900B95
:10071400852B8F0B832B831208008F008312851087
:100724001F309100910B942B00000000000000008A
:10073400900103108F0C8312031CA22B8514A42B8D
:10074400851000001D309100910BA62B00000000C5
:100754000000900A08301002031C9C2B00000000CB
:100764008312851421309100910BB62B831208005B
:10077400831685108511F030860083128514851543
:100784000F30860006080F3A0319C42B03308E007D
:100794008E0BCA2B831206080F3A0319C22B8C0145
:1007A400013092000C089300930ADA2B0310920D87
:1007B400930BD82B120886008D0100308A000D0897
:1007C40006200606031DF52B8511C83083128223EB
:1007D400C8308223851500308A000D0817208F2326
:1007E40004308C00FA2B8D0A10300D02031CDF2B11
:0C07F4008C0A04300C020318C22BD22B1C
:02400E00F13F80
:00000001FF



Free RS232

 Home | Applications | Industry Links | C++ Builder Stop | Micro Stop | Hex to Ascii Chart