CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PPS in 18F67J94 don't run

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karlosguay



Joined: 12 Jun 2013
Posts: 20

View user's profile Send private message

PPS in 18F67J94 don't run
PostPosted: Mon Mar 21, 2016 7:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 8:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 9:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 12:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2016 3:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2016 5:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2016 6:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2016 7:15 am     Reply with quote

Thanks gaugeguy and Ttelmah, with your notes now is running.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Mar 22, 2016 7:17 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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