View previous topic :: View next topic |
Author |
Message |
krigisk
Joined: 10 Nov 2011 Posts: 6
|
18F452 How to disable Int of RB1 |
Posted: Thu Nov 10, 2011 11:22 am |
|
|
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
|
|
Posted: Thu Nov 10, 2011 1:13 pm |
|
|
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
|
|
Posted: Thu Nov 10, 2011 2:40 pm |
|
|
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
|
|
Posted: Thu Nov 10, 2011 2:54 pm |
|
|
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
-
|
|
|
|
|