////////////////////////CODIGO//////////////////////////////////////////
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 10000000
#endif
void MCU_init(){
PORTD = 0X00;
TRISD = 0X00;
TRISC = 0b10000000;
TRISB = 0x0F;
OPTION_REG = 0x07;
}
void lectura_teclado(){
PORTB = 0b11101111;
if(RB0==0){
TXREG = '7';
__delay_ms(100);
}
else{
if(RB1==0){
TXREG = '4';
__delay_ms(100);
}
else{
if(RB2==0){
TXREG = '1';
__delay_ms(100);
}
else{
if(RB3==0){
TXREG = 'N';
__delay_ms(100);
}
}
}
}
PORTB = 0b11011111;
if(RB0==0){
TXREG = '8';
__delay_ms(100);
}
else{
if(RB1==0){
TXREG = '5';
__delay_ms(100);
}
else{
if(RB2==0){
TXREG = '2';
__delay_ms(100);
}
else{
if(RB3==0){
TXREG = '0';
__delay_ms(100);
}
}
}
}
PORTB = 0b10111111;
if(RB0==0){
TXREG = '9';
__delay_ms(100);
}
else{
if(RB1==0){
TXREG = '6';
__delay_ms(100);
}
else{
if(RB2==0){
TXREG = '3';
__delay_ms(100);
}
else{
if(RB3==0){
TXREG = '=';
__delay_ms(100);
}
}
}
}
PORTB = 0b01111111;
if(RB0==0){
TXREG = '/';
__delay_ms(100);
}
else{
if(RB1==0){
TXREG = 'x';
__delay_ms(100);
}
else{
if(RB2==0){
TXREG = '-';
__delay_ms(100);
}
else{
if(RB3==0){
TXREG = '+';
__delay_ms(100);
}
}
}
}
}
void configuracion_serial(){
//TRANSMISION
SPBRG = 64; // 9600 baudios
BRGH = 1;
SPEN = 1;
SYNC = 0;
//TXIE = 1; // enable transmision
TX9 = 0;
TXEN = 1;
//RECEPCION
CREN = 1;
RCIE = 1; //enable recepcion
RX9 = 0;
}
void main(){
MCU_init();
configuracion_serial();
while(1){
lectura_teclado();
}
}
////////////////////////////////////////////////////////////////////