|
|
View previous topic :: View next topic |
Author |
Message |
Audi80
Joined: 07 Sep 2007 Posts: 41
|
INT_RB Question |
Posted: Tue Dec 04, 2007 5:46 am |
|
|
Hi there. I´m trying to implement a simple software for a 4X3 keypad i´ve already made it work but when i add more functions to my pic it gets very unstable can anyone help me? Thanks in advance...
Code: | #include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
/////////////////////////////////////////////////////////////
#include "settings.h"
#include "stdlib.h"
#include "keyboard.h"
#include "rs232.h"
#include "card_reader.h"
#include "piccomm.h"
/////////////////////////////////////////////////////////////
void keypad();
void communications();
/////////////////////////////////////////////////////////////
#INT_RDA
void serial_interrupt(){
communications();
}
/////////////////////////////////////////////////////////////
#INT_RB
void card_reader_interrupt(){
keypad();
}
/////////////////////////////////////////////////////////////
void main() {
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
enable_interrupts(INT_RB);
atribui_porto();
rs232_inicializa();
set_get();
init_cartao();
init_keypad();
while(true){
le_cartao();
}
}
void keypad(){
carrega_buffer();
contem_teclas();
}
void communications(){
descodifica(ReceiveMsg(COM1));
} |
Plus the keypad driver...
Code: | ///////////////////////////////////////////////
// Driver Teclado 4X3 //
// Autor José Gonçalves 9/2007 //
// //
///////////////////////////////////////////////
// //
// Azul - C1 //
// Cinzento - C2 //
// Rosa - C3 //
// Vermelho - L4 //
// Castanho - L3 //
// Verde - L2 //
// Amarelo - L1 //
// //
///////////////////////////////////////////////
#define debounce 10
#define row1 PIN_B4
#define row2 PIN_B5
#define row3 PIN_B6
#define row4 PIN_B7
#define col1 PIN_B1
#define col2 PIN_B2
#define col3 PIN_B3
///////////////////////////////////////////////
char descodifica_tecla();
int contem_teclas();
void carrega_buffer();
char descarrega_buffer();
void set_get();
void init_keypad();
///////////////////////////////////////////////
int put=0;
int get=0;
char buffer_teclado [];
long contador=0;
///////////////////////////////////////////////
int contem_teclas(){
if(get==put){set_device_status(2,'1');}
else set_device_status(2,'5');
delay_ms(300);
return 1;
}
void init_keypad(){
output_high(col1);
output_high(col2);
output_high(col3);
}
void carrega_buffer(){
char aux;
aux = descodifica_tecla();
if(aux){
buffer_teclado[put]=aux;
++put;
++contador;
printf("%c %lu\r\n",aux,contador);
}
if(put==5){put=0;}// No caso do buffer estar cheio retorna á 1ª posição
}
char descarrega_buffer(){
char aux2;
aux2=buffer_teclado[get];
buffer_teclado[get]=0x00;
++get;
if(get==5){get=0;}
return aux2;
}
void set_get(){
get=0;
put=0;
memset(buffer_teclado,0,sizeof(buffer_teclado));
}
char descodifica_tecla(){
char tecla;
if(input(row1)){
output_low(col1);
if(!input(row1)){tecla='1';output_high(col1);}
output_low(col2);
if(!input(row1)){tecla='2';output_high(col2);}
output_low(col3);
if(!input(row1)){tecla='3';output_high(col3);}
}
if(input(row2)){
output_low(col1);
if(!input(row2)){tecla='4';output_high(col1);}
output_low(col2);
if(!input(row2)){tecla='5';output_high(col2);}
output_low(col3);
if(!input(row2)){tecla='6';output_high(col3);}
}
if(input(row3)){
output_low(col1);
if(!input(row3)){tecla='7';output_high(col1);}
output_low(col2);
if(!input(row3)){tecla='8';output_high(col2);}
output_low(col3);
if(!input(row3)){tecla='9';output_high(col3);}
}
if(input(row4)){
output_low(col1);
if(!input(row4)){tecla='*';output_high(col1);}
output_low(col2);
if(!input(row4)){tecla='0';output_high(col2);}
output_low(col3);
if(!input(row4)){tecla='#';output_high(col3);}
}
//init_keypad();
return tecla;
} |
After that i´ve connected it to Hyperterminal and even when i´m not pressing any key it stills entrer the interrupt. I thing that there may be a problem with floating pins. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Dec 04, 2007 10:39 am |
|
|
YES, floating pin could be your problem.
4x3 keypads will have pull-up resister(10k) on the row, or col, or both.
Sometimes this is done with the internal pull-ups on port B.
Add the pull-ups and try again.
perhaps
Code: | port_b_pullups(TRUE); |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 04, 2007 11:13 am |
|
|
Quote: | #include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT, NOLVP |
Are you using a low voltage programmer ? 99% of all programmers
are not LVP programmers. If you're using a normal programmer,
then you should enable the NOLVP fuse as shown above in bold.
If the PIC is in LVP mode, and the PGM pin (pin B3) goes high, the
PIC will go into programming mode. It will appear to lock-up or
behave in a flakey manner. |
|
|
Audi80
Joined: 07 Sep 2007 Posts: 41
|
|
Posted: Tue Dec 04, 2007 11:18 am |
|
|
Thanks i´ve got it right. I´ve changed the 3 columns of the keypad to C0 C1 e C2 pins and in the function that return the key i´ve set a return char to dont take to long responding... Thanks again. |
|
|
|
|
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
|