ZS1BFE
Member level 1
- Joined
- Nov 17, 2007
- Messages
- 40
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Cape Town South Africa
- Activity points
- 1,612
Hi all,
I use Pic16f877 with 4x4keypad.I cannot get the interrupt to work.I read the key OK, but then cannot prevent the code from scanning the same key again while the key is pressed.I tried to to keep it out by an IF statement, but then it only scans once when the program runs at startup??????
I use CCS C.
Here is some of the code I wrote.In the end I will add LCD to display key entries.
For now all I need is to scan the keys into var "first_key, etc" The keys are entered via 74C922 and port B4 is used to trigger the interrupt from output avaliable on the 74C922.
Data in is on B0 - B3.
#fuses NOLVP
set_tris_d(0x00);
set_tris_c(0x00);
set_tris_b(0xff);
int read_key = 0;
int key=5;
int row = 1;
int col = 0;
int b = 0;
int first_key = 4;
int second_key = 5;
int third_key = 6;
int cnt = 1;
int bit = 0 ;
#int_RB
RB_isr() {
delay_ms(160);
read_key = input_b() & 0b00001111 ;
if (read_key == 0b00000001)
key = 0 ;
if (read_key == 0b00001100)
key = 1 ;
if (read_key == 0b00001101)
key = 2 ;
if (read_key == 0b00001110)
key = 3 ;
if (read_key == 0b00001000)
key = 4 ;
if (read_key == 0b00001001)
key = 5 ;
if (read_key == 0b00001010)
key = 6 ;
if (read_key == 0b00000100)
key = 7 ;
if (read_key == 0b00000101)
key = 8 ;
if (read_key == 0b00000110)
key = 9 ;
if (read_key == 0b00000000) // *
key = 10 ;
if (read_key == 0b00000010) // #
key = 11 ;
if (read_key == 0b0000) // A
key = 12 ;
if (read_key == 0b00001011) // B
key = 13 ;
if (read_key == 0b00000111) // C
key = 14 ;
if (read_key == 0b00000011) // D
key = 15 ;
bit = 1;
cnt++;
if (cnt>3)
cnt = 1;
}
void main() {
port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(INT_RB);
enable_interrupts(global);
while(1)
{
if (input(pin_b4) == 1)
bit = 0;
output_d(key);
delay_ms(200);
if (cnt == 1)
first_key = key+ 48;
if (cnt == 2)
second_key = key + 48;
if (cnt == 3)
third_key = key + 48;
}
}
I hope this is clear.
THX
ZS1BFE
I use Pic16f877 with 4x4keypad.I cannot get the interrupt to work.I read the key OK, but then cannot prevent the code from scanning the same key again while the key is pressed.I tried to to keep it out by an IF statement, but then it only scans once when the program runs at startup??????
I use CCS C.
Here is some of the code I wrote.In the end I will add LCD to display key entries.
For now all I need is to scan the keys into var "first_key, etc" The keys are entered via 74C922 and port B4 is used to trigger the interrupt from output avaliable on the 74C922.
Data in is on B0 - B3.
#fuses NOLVP
set_tris_d(0x00);
set_tris_c(0x00);
set_tris_b(0xff);
int read_key = 0;
int key=5;
int row = 1;
int col = 0;
int b = 0;
int first_key = 4;
int second_key = 5;
int third_key = 6;
int cnt = 1;
int bit = 0 ;
#int_RB
RB_isr() {
delay_ms(160);
read_key = input_b() & 0b00001111 ;
if (read_key == 0b00000001)
key = 0 ;
if (read_key == 0b00001100)
key = 1 ;
if (read_key == 0b00001101)
key = 2 ;
if (read_key == 0b00001110)
key = 3 ;
if (read_key == 0b00001000)
key = 4 ;
if (read_key == 0b00001001)
key = 5 ;
if (read_key == 0b00001010)
key = 6 ;
if (read_key == 0b00000100)
key = 7 ;
if (read_key == 0b00000101)
key = 8 ;
if (read_key == 0b00000110)
key = 9 ;
if (read_key == 0b00000000) // *
key = 10 ;
if (read_key == 0b00000010) // #
key = 11 ;
if (read_key == 0b0000) // A
key = 12 ;
if (read_key == 0b00001011) // B
key = 13 ;
if (read_key == 0b00000111) // C
key = 14 ;
if (read_key == 0b00000011) // D
key = 15 ;
bit = 1;
cnt++;
if (cnt>3)
cnt = 1;
}
void main() {
port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(INT_RB);
enable_interrupts(global);
while(1)
{
if (input(pin_b4) == 1)
bit = 0;
output_d(key);
delay_ms(200);
if (cnt == 1)
first_key = key+ 48;
if (cnt == 2)
second_key = key + 48;
if (cnt == 3)
third_key = key + 48;
}
}
I hope this is clear.
THX
ZS1BFE