View previous topic :: View next topic |
Author |
Message |
JB
Joined: 25 Aug 2008 Posts: 5
|
port B interrupts on pic 16f1829 |
Posted: Mon Sep 19, 2011 3:47 pm |
|
|
The data sheet talks about interrupts on port 'B' for this device
yet the H file does not have an INT_RB or any INT_RBx #define statements.
Hummm. is this right or how do I fix it?
any help on this?
JB |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 19, 2011 5:46 pm |
|
|
What's your CCS compiler version ?
Do you have a push-button switch on a specific pin on Port B ?
If so, which pin ?
How are you testing this? Do you have an LED on another pin ?
Which pin ?
In other words, tell me your test setup. |
|
|
JB
Joined: 25 Aug 2008 Posts: 5
|
|
Posted: Tue Sep 20, 2011 8:24 am |
|
|
the compiler is 4.124
there are no INT_ RB in 16f1829.h
so the compiler chokes on the code
with
Undefined identifier INT_RB
I am sure it would work with the correct include file
I am using a signal generator to pin b4
and trying to catch the interrupt
Code: |
#include <16F1829.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
#define LED PIN_C0
#define DELAY 1000
#int_RB
void catch_RB_interrupt()
{
int x;
x = input_B();
output_toggle(pin_c1);
x = input_B();
}
void main()
{
enable_interrupts(INT_RB);
enable_interrupts(INT_RB4);
enable_interrupts(GLOBAL);
//Example blinking LED program
while(true){
output_low(LED);
delay_ms(DELAY);
output_high(LED);
delay_ms(DELAY);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 21, 2011 5:32 pm |
|
|
I made a work-around function to enable PortB interrupt-on-change
interrupts for the 16F1829. I don't have that PIC, so I just looked at the
.LST file while developing this. So I don't know if it will work for certain,
but I think it has a chance to work. This was checked with vs. 4.124.
Note only one interrupt enable works for interrupt-on-change for both
PortA and PortB. So you just use #int_ra for both ports. I created a
special routine (actually a macro) to enable PortB interrupt-on-change
interrupts. I then created some #defines for PortB interrupts, similar
to the ones for PortA in the 16F1829.h file.
The test program I have below is really setup for a push-button switch
on pin B4. That's why I enabled the internal pullup on pin B4, and it's why
I have the 10ms debounce delay in the #int_ra routine (just for test
purposes). Since you're using a signal generator, you could remove
those two lines.
Also, the interrupt-on-change pins have programmable input levels. They
can be either TTL or CMOS-Schmitt Trigger levels. I left them at the
default TTL level setting, but I put in a macro to allow changing them.
Code: |
#include <16F1829.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)
#define LED_PIN PIN_A0
#byte IOCAF = 0x393
#byte IOCBP = 0x394
#byte IOCBN = 0x395
#byte IOCBF = 0x396
#byte INLVLA = 0x38C
#byte INLVLB = 0x38D
#define clear_IOCA_flags() IOCAF = 0
#define clear_IOCB_flags() IOCBF = 0
#define clear_all_IOC_flags() IOCAF = 0; IOCBF = 0
// Parameter is a bitmask. 0 = TTL, 1 = Schmitt Trigger
#define set_PortA_input_levels(mask) INLVLA = mask // Bits 0-5 only
#define set_PortB_input_levels(mask) INLVLB = mask // Bits 4-7 only
#define INT_RB4 0x30100B08
#define INT_RB4_L2H 0x10100B08
#define INT_RB4_H2L 0x20100B08
#define INT_RB5 0x30200B08
#define INT_RB5_L2H 0x10200B08
#define INT_RB5_H2L 0x20200B08
#define INT_RB6 0x30400B08
#define INT_RB6_L2H 0x10400B08
#define INT_RB6_H2L 0x20400B08
#define INT_RB7 0x30800B08
#define INT_RB7_L2H 0x10800B08
#define INT_RB7_H2L 0x20800B08
#define enable_IOCB_interrupts(x) \
*(make8(x,1)) |= (int8)x; \
(make8(x,3) & 0x10) ? (IOCBP |= make8(x,2) ) : (IOCBP &= ~make8(x,2)); \
(make8(x,3) & 0x20) ? (IOCBN |= make8(x,2) ) : (IOCBN &= ~make8(x,2));
#int_ra
void rb_isr(void)
{
output_toggle(LED_PIN);
clear_IOCB_flags();
delay_ms(10);
}
//==========================================
void main()
{
port_b_pullups(0x10); // Parameter is a bitmask (for bit 4)
enable_IOCB_interrupts(INT_RB4_L2H);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
|
octopuss83
Joined: 06 Nov 2011 Posts: 13
|
INT_RB 16F1829 |
Posted: Thu May 23, 2013 12:35 am |
|
|
Thanks for this code JB.
In my case I have 3 interrupt to manage , can you write a:
"disable_IOCB_interrupts(x) "
disable_interrupts(RB4_L2H") works ?
how to disable this interrupt ?
Thanks _________________ ______________________
-- Octopuss --- |
|
|
|