Continue to Site

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.

  • 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.

PIC16F690 Hi tech C Interrupt problems

Status
Not open for further replies.

sundhir52

New Member
Hi, i am trying to get a external interrupt working in the PIC16F690, the code seems to be ok, but when i try simulating the program in the mplab sim it just jumps straight to the ISR holds there for a while and then jumps to the infinite loop.

i am using Hi tech C compiler, and trying to just toggle the PORTB on the external interrupt, but a am at a loss as to why its not working . . . .
any help will be greatly appreciated

Code:
#include <htc.h>
#include "delay.h"


//------------------------------------
void main(void) @0x00
{
	//Initialisation

	TRISA=0xFF;
	TRISB=0x00;
	TRISC=0x00;
	PORTA=0xFF;
	PORTB=0x00;
	PORTC=0x00;

	ANSEL=0x00;
	ANSELH=0x00;
	WPUB=0x00;
	

	GIE=1;
	INTEDG=1;
	PEIE=1;
	INTE=1;
		
 
	while(1)
	{

		PORTC=0x05;
		DelayMs(20);

		PORTC=0x06;
		DelayMs(20);
		
		PORTC=0x0A;
		DelayMs(20);
	
		PORTC=0x09;
		DelayMs(20);
		
	}	
	return;
}

//Interrupt Handler

static void interrupt int_handler(void) @ 0x10
{
	if ((INTF&&INTE))
	{
		PORTB=0XFF^PORTB;	
		INTF=0;
	}
	return;
}
 
I thought that the high/standard interrupt vector was at 08h .
Code:
# pragma code Inter=0x08
# pragma interrupt chk_isr
void Inter ( void) 
{
_asm
 GOTO chk_isr
_endasm


....


void chk_isr ( void)
//check the flags
 
Last edited:
You have a couple of things wrong with your code.
On the 16 series chip the interrupt vector is at location 4.
The return in the interrupt - remove it as you will miss the context restoring code.
Stop telling the compiler where to place code. It already knows and you will force it to do silly things.

Code:
#include <htc.h>
#include "delay.h"


//------------------------------------
void main(void)  [COLOR="red"]// @0x00   remove[/COLOR]{
	//Initialisation

	TRISA=0xFF;
	TRISB=0x00;
	TRISC=0x00;
	PORTA=0xFF;
	PORTB=0x00;
	PORTC=0x00;

	ANSEL=0x00;
	ANSELH=0x00;
	WPUB=0x00;
	

	GIE=1;
	INTEDG=1;
	PEIE=1;
	INTE=1;
		
 
	while(1)
	{

		PORTC=0x05;
		DelayMs(20);

		PORTC=0x06;
		DelayMs(20);
		
		PORTC=0x0A;
		DelayMs(20);
	
		PORTC=0x09;
		DelayMs(20);
		
	}	
	return;
}

//Interrupt Handler

static void interrupt int_handler(void) [COLOR="red"]// @ 0x10 remove[/COLOR]
{
	if ((INTF&&INTE))
	{
		PORTB=0XFF^PORTB;	
		INTF=0;
	}
	[COLOR="red"]//return;  remove[/COLOR]
}

Mike.
 
I thought that the high/standard interrupt vector was at 08h .
Code:
# pragma code Inter=0x08
# pragma interrupt chk_isr
void Inter ( void) 
{
_asm
 GOTO chk_isr
_endasm


....


void chk_isr ( void)
//check the flags

hey i tried you way but now it just gives me compile errors on the _asm instruction . . . ??
 
hey mike, thanks i have removed the addresses,
it still does not resolve my problem of the program just entering at the interrupt handler though
 
Last edited:
hey thanks it all works now, turns out there was a problem with my hi-tech C. I installed a 9.71a and now it works perfectly, thanks for all the help
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top