Keypad 4x4 PICC y PIC18F4550

Hola a todos. Actualmente me encuentro a menos de una semana para entregar mi practica de comunicación rs232 y manejo de la eeprom intetrna del Pic 18F4550. La comunicación no es el problema, en mi caso son los menús y que, por algún motivo mi teclado ya no funciona ni en proteus. E revisado el codigo y lo e vuelto a hacer unas 10 veces y no encuentro el error por el cual me encierra en un ciclo. Si alguien puede checarlo y hecharme una mano para que el teclado funcione le estaría eternamente agradecido. Abajo dejo el codigo.
Código:
#include <18F4550.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTHS                    //Internal Oscillator, HS used by USB
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV46                   //Brownout reset at 4.6V
#FUSES PUT                      //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 NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOMCLR                   //Master Clear pin disabled
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1                     //No PLL PreScaler
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES NOUSBDIV                 //USB clock source comes from primary oscillator
#FUSES NOVREGEN                 //USB voltage regulator disabled
#FUSES NOICPRT                  //ICPRT disabled

#use delay(internal=8000000)
#define LCD_TYPE 2
#include <lcd.c>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define alr pin_b3
int valor=0,valor2=0, pos=9, b=0,b1=0, b2=0, cont=0,t,dato;
int lsup, linf, dlsup=0, dlinf=1, dif;
int ingresandov=0,x=1;
long rpm, cc=512;
//float t;
char datosRx[4], bufferRx[4],tecla=' ';

void rsp(void);

#int_TIMER0
void  TIMER0_isr(void) 
{
   rpm=(get_timer1()*60);
   set_timer0(0);
   set_timer1(0);

}

#int_TIMER1
void  TIMER1_isr(void) 
{

}

#int_RDA
void  RDA_isr(void) 
{
    int i;
   output_toggle(pin_b5);
   bufferRx[cont] = getch();
   
   if (bufferRx[0] ==64 && bufferRx[3]==35)
   {
      for (i=0;i<4;i++)
      {
         datosRx[i]=bufferRx[i];
         bufferRx[i]=0;
      }
      lsup=datosRx[1];
      linf=datosRx[2];
      cont=0;
      lcd_putc("fDatosnActualizados...");
      delay_ms(300);
      lcd_putc("fTemp=");
   }
   else
      cont++;

}
#int_EXT
void  EXT_isr(void) 
{
   tecla=' ';
   dato=0;
   
   dato=input_e();
   switch (dato)
   {
      case 0:tecla='7';break;
      case 1:tecla='8';break;
      case 2:tecla='9';break;
      case 3:tecla='%';
             if (b==1)
             {  
               ingresandov=0;
               write_eeprom(dlsup,valor);
               delay_ms(20);
               lsup=valor;        
               write_eeprom(dlinf,valor2);
               delay_ms(20);
               linf=valor2;            
               lcd_putc("fDatosnActualizados");
               delay_ms(1500);
               valor=0;
               valor2=0;
               pos=9;
               dif=lsup-linf;
               b=0;
            }
            break;
      case 4:tecla='4';break;
      case 5:tecla='5';break;
      case 6:tecla='6';break;
      case 7:
                  tecla='x';
                  valor=0;                  
                  lcd_gotoxy(9,1);
                  lcd_putc("     ");
                  pos=9;
                  //lcd_gotoxy(pos,1);
            
               break;
      case 8:tecla='1';break;
      case 9:tecla='2';break;
      case 10:tecla='3';break;
      case 11:tecla='-';
              valor=0;
              write_eeprom(dlsup,255);
              delay_ms(20);
              write_eeprom(dlinf,255);
              delay_ms(20);
              lcd_putc("fIndica losnnuevos valores..");
              delay_ms(1000);
              valor=0;
              valor2=0;
              pos=9;
              rsp();                    
              break;
      case 12:tecla='O';break;
      case 13:tecla='0';break;
      case 14:tecla='=';break;
      case 15:tecla='+';break;
      default: break;
   }
   
   if (tecla>=48 && tecla<=57)
      {
      if (x==1)
      {
         valor=valor*10+(tecla-48);
         lcd_gotoxy(9,1);
         printf(lcd_putc,"%u",valor);
         delay_ms(1000);
        
      }
      if (x==2)
      {
         valor2=valor2*10+(tecla-48);
         lcd_gotoxy(9,2);
         printf(lcd_putc,"%u",valor2);
         delay_ms(1000);
        
      }
      
      }
  pos++;
}




void main()
{
   lcd_init();



   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_4);
   setup_timer_2(T2_DIV_BY_16,255,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(0);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

   // TODO: USER CODE!!

   set_tris_e(0xf);
   set_tris_b(0x01);
   port_b_pullups(true);
   rsp();
   set_pwm1_duty(cc);
   set_timer0(0);
   set_timer1(0);
   
   lcd_putc("fRPM xDFC Volts mA ");
   
   while(true)
   {
      set_adc_channel(0);
      delay_us(20);
      //v1=read_adc();
      //C°=-273.15K
      t=(((5.0/1024.0)*read_adc())/0.01)-273.15;
      lcd_gotoxy(1,2);
      printf(lcd_putc,"%4Lu %2u",rpm,t);
      output_high(pin_b1);
      output_low(pin_b2);

      if(t>lsup || t<linf)
         output_high(alr);
      else
         output_low(alr);
      printf("%2u/%u/%u/%Lurn",t,lsup,linf,rpm);
      delay_ms(1000);
   }
}

void rsp()
{
   lcd_putc("fLeyendon SetPoints...");
   delay_ms(1500);
   lsup=read_eeprom(dlsup);
   delay_ms(20);
   linf=read_eeprom(dlinf);
   delay_ms(20);
   
   printf(lcd_putc,"fLim sup=%u nLim inf=%u ",lsup,linf);
   delay_ms(1500);
   if (linf==255 && lsup==255)
   {
      lcd_putc("fIngresenValores...");
      delay_ms(1500);
      lcd_putc("fLim sup= nLim inf= ");
      ingresandov=1;
      while(ingresandov==1)
      {
         x=1;
         lcd_gotoxy(pos,1);
         lcd_putc("_");
         delay_ms(250);
         lcd_gotoxy(pos,1);
         lcd_putc(" ");
         delay_ms(250);
         if (valor<100 && valor>10)
         ingresandov=2;
      }

      while (ingresandov==2)
      {
         x=2;
         lcd_gotoxy(pos,2);
         lcd_putc("_");
         delay_ms(250);
         lcd_gotoxy(pos,2);
         lcd_putc(" ");
         delay_ms(250);
         if (valor2<100 && valor2>10)
         b=1;
      }
   }
   

   

}

Igual dejo una imagen de dónde se queda trabado el programa.
 

Adjuntos

  • rs232keypad.jpg
    rs232keypad.jpg
    89.1 KB · Visitas: 41
  • Teclado.txt
    7.5 KB · Visitas: 20
Atrás
Arriba