|
|
View previous topic :: View next topic |
Author |
Message |
JK Guest
|
16f886 INT_RB not working |
Posted: Fri Mar 05, 2010 8:23 pm |
|
|
I'm just trying to test PIN_B change interrupt writing program with CCS but it's not working at all.
The system of simple test is, to press button connected to RB7 port (pulled up) LED Light ON on port A1. That's it.
Test code is.....
Code: |
#include "c: \ xxxxxxxxxxxxxx "
#int_RB
void RB_isr(void)
{
int temp;
output_bit(pin_A1,1);
delay_ms(120);
temp = input_b();
}
void main()
{
set_tris_b(1);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
port_b_pullups(true);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!.,8
output_bit(pin_A1,1);
delay_ms(500);
output_bit(pin_A1,0); //LED blink test is working fine.
while(1)
{
}
}
|
It would be great if someone can help me out. Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 05, 2010 11:38 pm |
|
|
I've modified your program so it should work. If press the button on
pin B7 down, the LED will go on. When you release the button, the LED
will go off.
Code: |
#include <16F886.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#define SW_PIN PIN_B7
#define LED_PIN PIN_A1
#int_rb
void rb_isr(void)
{
int8 value;
output_toggle(LED_PIN);
delay_ms(10);
value = input(SW_PIN);
}
//============================
void main()
{
int8 temp;
output_low(LED_PIN);
temp = input(SW_PIN);
clear_interrupt(INT_RB);
enable_interrupts(INT_RB7);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
|
JK Guest
|
Thank you |
Posted: Sat Mar 06, 2010 1:10 am |
|
|
Thank you very much PCM programmer.
Now it is working perfectly.
I found myself that my understanding with 886 wasn't deep enough.
Thank you 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
|