0% found this document useful (0 votes)
14 views5 pages

P Teclado

The document defines functions for initializing an MCU and reading inputs from a keypad to display on an LCD. It initializes the MCU and keypad interrupts, then enters a loop to continuously check for keypad presses and display the keys on the LCD.

Uploaded by

zastonirto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

P Teclado

The document defines functions for initializing an MCU and reading inputs from a keypad to display on an LCD. It initializes the MCU and keypad interrupts, then enters a loop to continuously check for keypad presses and display the keys on the LCD.

Uploaded by

zastonirto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <hidef.

h>
#include "derivative.h"

#define segundo 0x01


#define E PTAD_PTAD0
#define RS PTAD_PTAD1
void MCUinit (void);
void retardoRTI (void);
void init_LCD(void);
void enable(void); //Función de enable
void comando(unsigned char y); //Enmascaramiento
void dato(unsigned char j);
void KBIinit(void); //Inicialización de KBI
void IRQ_KBI(void); //Bandera de KBI
void retardoKBI (void);

void main(void) {
SOPT1=0x12;
MCUinit();
KBIinit();
EnableInterrupts;
init_LCD();
for(;;) {

}
}

void MCUinit (void)


{
PTBDD=0xF0;
PTADD=0x07; // PTA del 0-2 como salida
PTBPE_PTBPE3=1;
PTBPE_PTBPE2=1;
PTBPE_PTBPE1=1;
PTBPE_PTBPE0=1;
}

void retardoRTI (void)


{
SRTISC=segundo;
while(SRTISC_RTIF==0);
SRTISC_RTIACK=1;
SRTISC=0x00;
}

void enable(void){
E=1;
retardoRTI();
E=0;
}

void init_LCD(void){
unsigned char i=0;
unsigned char tabla[7]={0x33, 0x32, 0x28, 0x0F, 0x06, 0x01, 0x00};
while(i!=7){
comando(tabla[i]);
i++;
}
}

void dato(unsigned char j){


unsigned char data;
data=j;
data=data&0xF0;
RS=1;
PTBD=data;
enable();
data=j;
data=data&0x0F;
data=data<<4;
PTBD=data;
enable();
PTBD = 0x00;
}

void comando (unsigned char y){


unsigned char a;
a=y;
a=a&0xF0;
PTBD=a;
RS=0;
enable();
a=y;
a=a&0x0F;
a=a<<4;
PTBD=a;
enable();
RS=1;
}

void retardoKBI (void)


{
unsigned int x = 0xFFFF;
while(x!=0){
x=x-1;
}
}

void KBIinit(void){ //Funcion de KBI


KBIES = 0x00; //Detectar Bajada
KBISC = 0x02; //Detectar transición
KBIPE = 0xF0; //PTB Activado
}

interrupt 18 void IRQ_KBI(void){ //Interrupción


unsigned char filas = PTBD;
DisableInterrupts;
KBISC_KBACK=1; //Apagar

//FILA 1
while(filas == 0x0E){
PTBD = 0xE0;
if(PTBD == 0xEE){
dato('1');
while(PTBD == 0x0E){}
filas =0x00;
}
PTBD = 0xD0;
if(PTBD == 0xDE){
dato('2');
while(PTBD == 0x0E){}
filas =0x00;
}
PTBD = 0xB0;
if(PTBD == 0xBE){
dato('3');
while(PTBD == 0x0E){}
filas =0x00;
}
PTBD = 0x70;
if(PTBD == 0x7E){
dato('A');
while(PTBD == 0x0E){}
filas =0x00;
}

//FILA 2
while(filas == 0x0D){
PTBD = 0xE0;
if(PTBD == 0xED){
dato('4');
while(PTBD == 0x0D){}
filas =0x00;
}
PTBD = 0xD0;
if(PTBD == 0xDD){
dato('5');
while(PTBD == 0x0D){}
filas =0x00;
}
PTBD = 0xB0;
if(PTBD == 0xBD){
dato('6');
while(PTBD == 0x0D){}
filas =0x00;
}
PTBD = 0x70;
if(PTBD == 0x7D){
dato('B');
while(PTBD == 0x0D){}
filas =0x00;
}

}
//FILA 3
while(filas == 0x0B){
PTBD = 0xE0;
if(PTBD == 0xEB){
dato('7');
while(PTBD == 0x0B){}
filas =0x00;
}
PTBD = 0xD0;
if(PTBD == 0xDB){
dato('8');
while(PTBD == 0x0B){}
filas =0x00;
}
PTBD = 0xB0;
if(PTBD == 0xBB){
dato('9');
while(PTBD == 0x0B){}
filas =0x00;
}
PTBD = 0x70;
if(PTBD == 0x7B){
dato('C');
while(PTBD == 0x0B){}
filas =0x00;
}

//FILA 4
while(filas == 0x07){
PTBD = 0xE0;
if(PTBD == 0xE7){
dato('*');
while(PTBD == 0x07){}
filas =0x00;
}
PTBD = 0xD0;
if(PTBD == 0xD7){
dato('0');
while(PTBD == 0x07){}
filas =0x00;
}
PTBD = 0xB0;
if(PTBD == 0xB7){
dato('#');
while(PTBD == 0x07){}
filas =0x00;
}
PTBD = 0x70;
if(PTBD == 0x77){
dato('D');
while(PTBD == 0x07){}
filas =0x00;
}

PTBD=0x00;

EnableInterrupts;
}

You might also like