CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F452 How to disable Int of RB1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
krigisk



Joined: 10 Nov 2011
Posts: 6

View user's profile Send private message MSN Messenger

18F452 How to disable Int of RB1
PostPosted: Thu Nov 10, 2011 11:22 am     Reply with quote

Hi guys. It's my first post and I have a problem.
I need to disable the interrupt function of the RB1 and RB2 of the 18F452. I have a keypad connected in the portB and I cannot change for many reasons.
I was using 16f877a, but my code it's too large for the memory, so I decide to change to the 18F family.

Can anyone help me?

Thank you guys
Code:


#include <18f452.h>         // identifica microcontrolador alvo
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP
#use delay (clock=4000000)  // <- define cristal para 4Mhz. Para outros valores, mude e recompile.
#include <flexstdio.h>


#int_RB

void trata_emerg(void)
{
   lcd_init();
   lcd_putc("\fInterrupcao");
   clear_interrupt(INT_RB);
}


void main()       // função principal
  {
  int16 senha_mestre=1234;
  int16 senha_dig,senha_dig2,senha_unlock;
  int16 valor1,valor2,select,errada;
 
  enable_interrupts(INT_RB);
  enable_interrupts(GLOBAL);
 
  output_a(0x00);  // desliga todo PORTA
  output_b(0x00);  // desliga todo PORTB
  output_c(0x00);  // desliga todo PORTC
  output_d(0x00);  // desliga todo PORTD
 
  lcd_init();
  lcd_putc("\fBem vindo!");
  delay_ms(500);
 
     while(true)
       {
         lcd_putc("\fSelecione uma\nopcao a seguir");
         delay_ms(500);
         opcoes:
            lcd_putc("\f1.Liberar acesso\n2.Criar usuario");
            delay_ms(500);
            lcd_putc("\f3.Soar alarme\n4.Bloquear tudo");
            delay_ms(500);
            lcd_putc("\fOpcao:\n=>");
            select=cusco_readkbd(0);
               switch(select)
               {
                  case 1:
                  goto acesso;
                  case 2:
                  goto cadastro;
                  case 3:
                  goto alarme;
                  case 4:
                  goto bloqueio;
                  default:
                  lcd_putc("\fOpcao invalida");
                  delay_ms(500);
                  goto opcoes;
               }
       }
       
acesso:

   lcd_putc("\fPara acessar\ndigite a senha");
   delay_ms(500);
   lcd_putc("\fSenha de usuario\n=>");
   senha_dig=cusco_readkbd(0);
      if(senha_dig==valor1){
         lcd_putc("\fAcesso liberado!");
         output_high(PIN_A0);
         delay_ms(50);
         output_low(PIN_A0);
         delay_ms(50);
         output_high(PIN_A0);
         delay_ms(50);
         output_low(PIN_A0);
         output_high(PIN_A0);
         delay_ms(50);
         output_low(PIN_A0);
         output_high(PIN_A0);
         delay_ms(50);
         output_low(PIN_A0);
         goto opcoes;
      }
      else{
         errada++;
            if(errada==3){
               lcd_putc("\f3 tentativas sem\nsucesso!");
               delay_ms(500);
               lcd_putc("\fAtivar bloqueio:\n=>bloqueado");
               delay_ms(500);
               goto bloqueio;
            }
            else{
               lcd_putc("\fSenha errada\nTente novamente");
               delay_ms(500);
               goto acesso;
            }
      }
     
cadastro:

   lcd_putc("\fSenha mestre\n=>");
   senha_dig2=cusco_readkbd(0);
      if(senha_dig2==senha_mestre){
        break;
      }
      else{
         lcd_putc("\fSenha errada");
         delay_ms(500);
         goto cadastro;
      }
   lcd_putc("\fDefinicao de\nsenha de usuario");
   delay_ms(500);
   lcd_putc("\fSenha desejada\n=>");
   valor1=cusco_readkbd(0);
   lcd_putc("\fDigite novamente\n=>");
   valor2=cusco_readkbd(0);
      if(valor1==valor2){
         lcd_putc("\fSenha definida!");
         delay_ms(500);
         //write_eeprom(0x00, 0x50);
         goto opcoes;
      }
      else{
         lcd_putc("\fVoce digitou\nalgo errado");
         delay_ms(500);
         goto cadastro;
      }
       
alarme:
   lcd_putc("\fAlarme");
   output_high(PIN_A0);
   delay_ms(2);
   goto opcoes;
         bloqueio:
            output_high(PIN_A0);
            lcd_putc("\fSistema \nbloqueado");
            delay_ms(500);
            lcd_putc("\fSenha mestre:\n=>");
            senha_unlock=cusco_readkbd(0);
               if(senha_unlock==senha_mestre){
                  lcd_putc("\fSistema liberado");
                  delay_ms(500);
                  output_low(PIN_A0);
                  goto opcoes; 
               }
               else{
                  lcd_putc("\fSenha errada");
                  delay_ms(500);
                  goto bloqueio;
               }     
  }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 10, 2011 1:13 pm     Reply with quote

Quote:
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);

I need to disable the interrupt function of the RB1 and RB2 of the 18F452.



18F452 doesn't have #int_rb interrupts on pins B1 and B2. It only has
them on pins B4-B7. The 18F452 data sheet says:
Quote:

8.8 PORTB Interrupt-on-Change

An input change on PORTB<7:4> sets flag bit RBIF
(INTCON<0>). The interrupt can be enabled/disabled
by setting/clearing enable bit, RBIE (INTCON<3>).
Interrupt priority for PORTB interrupt-on-change is
determined by the value contained in the interrupt
priority bit, RBIP (INTCON2<0>).

Link to data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf
krigisk



Joined: 10 Nov 2011
Posts: 6

View user's profile Send private message MSN Messenger

PostPosted: Thu Nov 10, 2011 2:40 pm     Reply with quote

PCM PROGRAMMER thanks for your aswer.

I change my keypad position to the portC, works fine.

Now I need to activate a emergency button in the portB.

Do you know a better way to do that? Cause I try the #INT_BUTTON and doesn't works :/

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 10, 2011 2:54 pm     Reply with quote

This thread discusses using #int_ext on pin B0:
http://www.ccsinfo.com/forum/viewtopic.php?t=45315

You need to connect a push-button switch to pin B0 as shown below.
Instead of using an external resistor shown below, you could enable
PortB pull-ups by using the port_b_pullups() function.
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin RB0                        |             
                              --- GND
                               -
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group