View previous topic :: View next topic |
Author |
Message |
karlosguay
Joined: 12 Jun 2013 Posts: 20
|
PPS in 18F67J94 don't run |
Posted: Mon Mar 21, 2016 7:57 am |
|
|
Hi, i have a 18F67J94 and i need to use Interrupt On Change with pins RB0 to RB5. These pins are PPS and then i use this code:
Code: |
#pin_select IOC0=PIN_B0
#pin_select IOC1=PIN_B1
#pin_select IOC2=PIN_B2
#pin_select IOC3=PIN_B3
#pin_select IOC4=PIN_B4
#pin_select IOC5=PIN_B5
IOCP=0x001111111;
IOCN=0x001111111;
enable_interrupts (INT_IOC);
enable_interrupts (GLOBAL);
int HePulsado=0;
#INT_IOC
void QueHePulsado()
{
HePulsado=7;
}
void main()
{
WHILE (true)
{
printf HePulsado;
}
}
|
Where is the problem?? I think i haven't any interruption.
My CCS version is 5.051
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Mar 21, 2016 8:21 am |
|
|
As posted, it wouldn't.....
These lines:
IOCP=0x001111111;
IOCN=0x001111111;
enable_interrupts (INT_IOC);
enable_interrupts (GLOBAL);
need to be inside the code, not floating around in mid-air....
Also, you don't clear the IOC registers in the interrupt, so it'll never exit. |
|
|
karlosguay
Joined: 12 Jun 2013 Posts: 20
|
|
Posted: Mon Mar 21, 2016 9:24 am |
|
|
Sorry, you are right.
The code only is a example
Code: |
#pin_select IOC0=PIN_B0
#pin_select IOC1=PIN_B1
#pin_select IOC2=PIN_B2
#pin_select IOC3=PIN_B3
#pin_select IOC4=PIN_B4
#pin_select IOC5=PIN_B5
int HePulsado=0;
#INT_IOC
void QueHePulsado()
{
HePulsado=7;
}
void main()
{
IOCP=0x001111111;
IOCN=0x001111111;
enable_interrupts (INT_IOC);
enable_interrupts (GLOBAL);
WHILE (true)
{
printf HePulsado;
}
}
|
Now i dont understand which register i need clear |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Mar 21, 2016 12:13 pm |
|
|
There are two separate things (on most simpler PIC's only one).
First the change bits are triggered when the selected inputs do not match the register latches. The latches are set whenever the port is read. So once a change triggers, the port _must_ be read. You only actually need to read a single bit in the port, but unless this is done, the interrupt cannot be cleared. Result the interrupt will trigger forever...
On your PIC there is also an IOCF register, which contains separate flags for which bit has triggered. Normally you would test this so you can know which pin has triggered the interrupt. This also should be cleared. |
|
|
karlosguay
Joined: 12 Jun 2013 Posts: 20
|
|
Posted: Tue Mar 22, 2016 3:02 am |
|
|
Thanks Ttelmah:
Now my code is
Code: |
#pin_select IOC0=PIN_B0
#pin_select IOC1=PIN_B1
#pin_select IOC2=PIN_B2
#pin_select IOC3=PIN_B3
#pin_select IOC4=PIN_B4
#pin_select IOC5=PIN_B5
int HePulsado=0;
#INT_IOC
void QueHePulsado()
{
int8 leo;
leo=input_b();
if (IOCF0==1) HePulsado=1;
else{
if (IOCF1==1) HePulsado=2;
else{
if (IOCF2==1) HePulsado=3;
else{
if (IOCF3==1) HePulsado=4;
else{
if (IOCF4==1) HePulsado=5;
else{
if (IOCF5==1) HePulsado=6;
else{
HePulsado=9;
}
}
}
}
}
}
HePulsado=7;
IOCF=0;
}
void main()
{
IOCP=0x001111111;
IOCN=0x001111111;
enable_interrupts (INT_IOC);
enable_interrupts (GLOBAL);
WHILE (true)
{
printf HePulsado;
}
}
|
but the same problem. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Tue Mar 22, 2016 5:55 am |
|
|
Are you sure:
1) That your chip is actually running. The old flash an LED test.
2) That you have normal I/O enabled on the pins involved. Things like the LCD charge pump take priority over normal operation.
3) Analog disabled on all the pins.
As a general rule, vcut your code down to the minimum, and post a complete program that shows what you are doing. So many bit are omitted from what you post.
Try something basic, like:
Code: |
#include <18F67J94.h>
#device ADC=16
#fuses STVREN,FRC_PLL,NOPROTECT,NOXINST,NODEBUG,BROWNOUT_SW,NOWDT
#use delay(internal=32MHz)
#PIN_SELECT U1RX=PIN_A3
#PIN_SELECT U1TX=PIN_A2
#use RS232(UART1,ERRORS,baud=9600)
#pin_select IOC0=PIN_B0
#pin_select IOC1=PIN_B1
#pin_select IOC2=PIN_B2
#pin_select IOC3=PIN_B3
#pin_select IOC4=PIN_B4
#pin_select IOC5=PIN_B5
#byte IOCP=getenv("SFR:IOCP")
#byte IOCN=getenv("SFR:IOCN")
#byte IOCF=getenv("SFR:IOCF")
int8 status=0;
#INT_IOC
void change(void)
{
int8 temp;
temp=input_b();
status=IOCF;
IOCF=0;
}
void main(void)
{
setup_lcd(LCD_DISABLED);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC);
setup_act(ACT_DISABLED);
setup_dsm(DSM_DISABLED);
setup_vref(VREF_OFF);
setup_spi(SPI_DISABLED);
setup_psp(PSP_DISABLED); //ensure all stuff is off
set_tris_b(0xFF); //ensure port is input
IOCF=0;
enable_interrupts(GLOBAL);
enable_interrupts(INT_IOC);
while(TRUE)
{
delay_ms(1000);
printf("%d",status);
}
}
|
|
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Mar 22, 2016 6:34 am |
|
|
karlosguay
IOCP=0x001111111;
IOCN=0x001111111;
Why are you loading IOCP and IOCN with 32 bit hex values?
Do you mean to use a binary value instead? 0b instead of 0x? |
|
|
karlosguay
Joined: 12 Jun 2013 Posts: 20
|
|
Posted: Tue Mar 22, 2016 7:15 am |
|
|
Thanks gaugeguy and Ttelmah, with your notes now is running. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 22, 2016 7:17 am |
|
|
Suddenly the hills are alive with fundamentally lacking code for the "18F67J94" - so i am assuming that any post of late that has this tell evaluates to:
#define 18F67J94=student_homework |
|
|
|