//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
// Sacar el comment para seleccionar el puerto, sino por default es PORTE
//#define use_porta_kbd TRUE
//#define use_portb_kbd TRUE
//#define use_portc_kbd TRUE
//#define use_portd_kbd TRUE
// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
#if defined(__PCH__) // Caso PIC18
#if defined use_porta_kbd
#byte kbd = 0xF80 // Direccion PORTA
#elif defined use_portb_kbd
#byte kbd = 0xF81 // Direccion PORTB
#elif defined use_portc_kbd
#byte kbd = 0xF82 // Direccion PORTC
#elif defined use_portd_kbd
#byte kbd = 0xF83 // Direccion PORTD
#else
#byte kbd = 0xF84 // Direccion PORTE
#endif
#else // Caso PIC16
#if defined use_porta_kbd
#byte kbd = 5 // on to port A
#elif defined use_portb_kbd
#byte kbd = 6 // Direccion PORTB
#elif defined use_portc_kbd
#byte kbd = 7 // Direccion PORTC
#elif defined use_portd_kbd
#byte kbd = 8 // Direccion PORTD
#else
#byte kbd = 9 // on to portE
#endif
#endif
#if defined use_porta_kbd
#define set_tris_kbd(x) set_tris_a(x)
#elif defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#elif defined use_portc_kbd
#define set_tris_kbd(x) set_tris_c(x)
#elif defined use_portd_kbd
#define set_tris_kbd(x) set_tris_d(x)
#else
#define set_tris_kbd(x) set_tris_e(x)
#endif
#include <18F6722.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=8000000)
#BYTE PORTA=0XF80
#BYTE PORTB=0XF81
#BYTE PORTC=0XF82
#BYTE PORTD=0XF83
#BYTE PORTE=0XF84
#BYTE PORTF=0XF85
#BYTE PORTG=0XF86
#BYTE TRISA=0XF92
#BYTE TRISB=0XF93
#BYTE TRISC=0XF94
#BYTE TRISD=0XF95
#BYTE TRISE=0XF96
#BYTE TRISF=0XF97
#BYTE TRISG=0XF98
#include <lcd.c>
#include <kbde.c>
char a; //Caracteres teclado 4x4
int b;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
lcd_init();
kbd_init();
set_tris_D(0x00);
set_tris_E(0xff);
printf(lcd_putc,"\f***BIENVENIDO***\n****************"); //Menu principal
delay_ms(2000);
printf(lcd_putc,"\fdigito:");
while(true)
{
a=kbd_getc(); //Comprueba si es pulsada alguna tecla
b=a-48;
if(a!=0){
printf(lcd_putc,"\fdigito:%u",b);
}
}
}