//archivo key4x4.c
#include <16F628A.h>
#FUSES NOWDT, INTRC_IO, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD
//CONFIG INTRC_OSC_NOCLKOUT , WDT_OFF , PWRTE_OFF , BODEN_OFF , LVP_OFF , PWRTE_OFF , CP_OFF
#use delay(clock=4000000)
#define use_portb_kbd 1
#define tecla 5
#include <teclado4.h>
void main()
{
set_tris_a(0b10000000);
set_tris_b(0b11110000);
#asm
; BSF STATUS,RP0
bsf 3,5
; clrf OPTION
clrf 1
; bcf status,rp0
bcf 3,5
#endasm
port_b_pullups(true);
// setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
*tecla=0;
do{
while(input_state(PIN_A4)==0){
kbd_getc();}
while(input_state(PIN_A7)==1){
#asm
nop
#endasm
}
*tecla=0;
}while(true);
}
//teclado4.h
#define portb 6
#define L1 0b00000111
#define L2 0b00001011
#define L3 0b00001101
#define L4 0b00001110
void kbd_getc()
{
char temp;
*portb=L1;
temp=portb;
temp=temp&0xF0;
switch (temp){
case 0b11100000:*tecla=0x10;
break;
case 0b11010000:*tecla=0x11;
break;
case 0b10110000:*tecla=0x12;
break;
case 0b01110000:*tecla=0x13;
break;}
*portb=L2;
temp=portb;
temp=temp&0xF0;
switch (temp){
case 0b11100000:*tecla=0x14;
break;
case 0b11010000:*tecla=0x15;
break;
case 0b10110000:*tecla=0x16;
break;
case 0b01110000:*tecla=0x17;
break;}
*portb=L3;
temp=portb;
temp=temp&0xF0;
switch (temp){
case 0b11100000:*tecla=0x18;
break;
case 0b11010000:*tecla=0x19;
break;
case 0b10110000:*tecla=0x1A;
break;
case 0b01110000:*tecla=0x1B;
break;}
*portb=L4;
temp=portb;
temp=temp&0xF0;
switch (temp){
case 0b11100000:*tecla=0x1C;
break;
case 0b11010000:*tecla=0x1D;
break;
case 0b10110000:*tecla=0x1E;
break;
case 0b01110000:*tecla=0x1F;
break;}
*portb=0x0f;
return;
}