• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PORTB interruption with CCS Compiler ?

Status
Not open for further replies.

loup-garou

New Member
Hello all,

My code which consists on lightening a LED connected to RA3 with a push-button connected to RB6 was compiled with success (0 error , 2 warnings of conditions always true and false) but did no function when I tried to simulate it with ISIS however it was a simple one (see below),

would anybody help me in correcting it or give me another correct code written with the same compiler ?


thanks in advance.


I use PCW 4.057 version of CCS.


Code:
#include "C:\Documents and Settings\test 1.h"
  #ZERO_RAM


#define RB6 PIN_B6  

int1 flag6;

#int_RB            
void RB_isr()          
{
if (!RB6) flag6=1;   
delay_ms(300);
}                 


void main()
{

   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);



   ext_int_edge(H_TO_L); 
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_RB); 
   enable_interrupts(GLOBAL);
   
   set_tris_b(0xff);         
   set_tris_a(0x00);        
   

 flag6=0;
 
while(1)

  {

  if (flag6)
     {
     output_high(pin_a3);
     flag6=0; 
     }
 
  }

   

}
 
Last edited:

kchriste

New Member
Forum Supporter
You shouldn't have a delay in an interrupt routine. You could do this without using interrupts. Which PIC are you using?
 

kchriste

New Member
Forum Supporter
I don't use that compiler but, you need to clear the RBIF bit in the INTCON register at the end of the interrupt routine. It is also recommended that you read from portB and then clear the RBIF bit in the INTCON register when you initialize the PIC.
 

Pommie

Well-Known Member
Most Helpful Member
AFAIA, the CCS compiler clears the interrupt flag for you. Whether it reads portb as well I can only guess but portb must be read before clearing RBIF in the ISR. I don't like compilers that help me in that way.

Mike.
 

loup-garou

New Member
I found in CCS Manual this interruption relevant functions:


disable_interrupts() : Disables the specified interrupt.

enable_interrupts() : Enables the specified interrupt.

ext_int_edge() : Enables the edge on which the edge interrupt should trigger. This can be either rising or falling edge.

clear_interrupt() : This function will the specified interrupt flag. This can be used if a global isr is used, or to prevent an interrupt from being serviced.

-------------


so I wrote clear_interrupt(RB6) in the end of the interrupt routine but this did not make any change, is this correct ?


Code:
#int_RB            
void RB_isr()          
{
if (!RB6) flag6=1;   
clear_interrupt(RB6);
}
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
Yes, the read of RB6 will clear the mismatch but I would guess that the function should be clear_interrupt(RBIF).

As 3v0 states look at the asm if your unsure.

Mike.
 

loup-garou

New Member
When in doubt about what the compiler is doing look at the generated ASM code in MPLAB. VIEW>DISASSEMBLY_LISTING
Yes, the read of RB6 will clear the mismatch but I would guess that the function should be clear_interrupt(RBIF).

As 3v0 states look at the asm if your unsure.

Mike.
unforunatly, I don't understand well ASM, I've never programmed with this language.

but thank you for the advice.
 
Last edited:

3v0

Coop Build Coordinator
Forum Supporter
unforunatly I don't understand ASM.
This is a good time to get started. Look up each opcode in the data sheet for the processor family. You do not have to understand every detail this time, just identify where the interupts are cleared and disabled/enabled.

Everyone should learn assembly at least to the point where he understands what the compiler is doing.
 

loup-garou

New Member
This is a good time to get started. Look up each opcode in the data sheet for the processor family. You do not have to understand every detail this time, just identify where the interupts are cleared and disabled/enabled.

Everyone should learn assembly at least to the point where he understands what the compiler is doing.
thank you 3V0 !! ;)
 

LUNAR

New Member
PIC18F4550 interrupt HELP PLEASE

HELLO i am using pic18f4550, i just want to configure the int0 to blink and led, but i am not having any luck please see my code and tell me where i am wrong. i am really stuck. thanks.
//*************************************************************************************************
//test code for int0, blink led on portD on receving interrupt

#include <p18f4450.h>
void main (void);
void InterruptHandlerHigh (void);


void main ()
{
int i=0;
INTCON2bits.INTEDG0=1;//m interrupt is rising edge
INTCONbits.INT0IE=1;//m enable interrupt

INTCONbits.GIEH = 1; //enable global interrupts
TRISB = 1; //set port b as input
TRISD=0; //set port d as output

while(1);//move in loop, gets out on receving interrupt and then comes back.

}//end main


// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void
InterruptHandlerHigh ()
{ int i=0;
int j=0;

if (INTCONbits.INT0F)
{
INTCONbits.INT0IE=0;//m disable the interrupt

for(j=0;j<4;j++)//toggle the bit0 or portD on receiving interrupt
{
LATDbits.LATD0 = 1;
for( i=0;i<40000;i++);
LATDbits.LATD0 = 0;
for( i=0;i<40000;i++);
}

INTCONbits.INT0F=0; //m reset the flag
}
INTCONbits.INT0IE=1;//m enable the interrupt
}

//----------------------------------------------------------------------------
//*************************************************************************************************
 

futz

Active Member
HELLO i am using pic18f4550, i just want to configure the int0 to blink and led, but i am not having any luck please see my code and tell me where i am wrong. i am really stuck. thanks.
Hey Lunar. If you can, start a new thread of your own. And when you post code, always use the Code tags. To do this, click on the # symbol in the posting menu just before pasting your source code. You can also do it by typing [code] before your source and [/code] after it. This preserves the formatting of your source code so it stays readable and people will actually look at it.

Like this:
Code:
#include <p18f4450.h>
void InterruptHandlerHigh (void);

void main()
{
	int i=0;
	INTCON2bits.INTEDG0 = 1;	//m interrupt is rising edge
	INTCONbits.INT0IE = 1;		//m enable interrupt
	INTCONbits.GIEH = 1;		//enable global interrupts
	TRISB = 1;			//set port b as input
	TRISD = 0;			//set port d as output

	while(1);	//move in loop, gets out on receiving interrupt and then comes back.
}

// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
	_asm
	goto	InterruptHandlerHigh	//jump to interrupt routine
	_endasm
}

// High priority interrupt service routine
#pragma code
#pragma interrupt InterruptHandlerHigh

void InterruptHandlerHigh()
{
	int i=0;
	int j=0;

	if(INTCONbits.INT0F)
	{
		INTCONbits.INT0IE=0;	//m disable the interrupt

		for(j=0;j<4;j++)	//toggle the bit0 or portD on receiving interrupt
		{
			LATDbits.LATD0 = 1;
			for( i=0;i<40000;i++);
			LATDbits.LATD0 = 0;
			for( i=0;i<40000;i++);
		}

		INTCONbits.INT0F=0;	//m reset the flag
	}
	INTCONbits.INT0IE=1;		//m enable the interrupt
}
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top