#include <pic.h>
#include <htc.h>
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS);
void main(void)
{
unsigned char Previous,Keys,Edges;
unsigned char segment[] ={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
ANSEL = 0x00; //select all PORTs digital i/o
ANSELH = 0x00;
TRISA = 0xFF; //select PORTA as input
TRISB = 0x00; //select PORTB as output
TRISC= 0x00; //PORTC SET AS OUTPUT
PORTB=0x00;
PORTA= 0x00;
Previous=0;
while(1){
_delay(20000); //debounce delay (assumed 4MHz Crystal)
Keys=PORTA; //read the port
Edges=Keys^Previous;//Edges = keys that have changed
Edges&=Keys; //edges = key that went from 0 to 1.
Previous=Keys; //keep copy of new keys.
if(Edges&0x08) //RA3 Pressed?
PORTB^=0x10; //yes, so toggle RB4
if(Edges&0x10) //RA4 Pressed?
PORTB^=0x20; //yes, so toggle RB5
}
}