Jump to content
BBC

16f1933 Interrupt Problem

Recommended Posts

I am having trouble using the debugger buttons to generate an interrupt-on-change for the 16F1933. The following code is similar to that posted by Daz on 2 Dec. 2010. The code is intended to simply light a led connected to porta when portb.0 button is pushed. The button block does not activate the interrupt-on-change for the portb input(s). Any help would be greatly appreciated.

 

#include <system.h>
#include <stdlib.h>



// Target PIC16F1933 configuration word
#pragma DATA _CONFIG1, _FOSC_XT & _WDTE_OFF &  _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
#pragma DATA _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _DEBUG_ON & _LVP_OFF

// Set PIC clock frequency
#pragma CLOCK_FREQ 4000000




#define	button1	portb.0
#define	led1	porta.0
unsigned char flag1;

// ***************** Interrupt Service Routine *********************
//
// 	Called from portb change of state
// 
// ******************************************************************

void interrupt(void)
 {
//Handle external interrupt
if( intcon & (1<<IOCIF) )
{
	if(button1){flag1 = 1;}
	clear_bit( intcon, IOCIF );
}
 }

//****************** init_processor() ***************************
//
//	Set up PIC16F1933 internal registers
//
//	Parameters:	
//		Entry: none
//		Exit: none
//
// **************************************************************
void init_processor()
{
	// Configure port A

	ansela = 00000000b;	// porta all digital
	trisa = 00000000b;		// porta all outputs



	// Configure port B

	anselb = 00000000b;		// portb all digital 
	trisb = 11111111b;	  // portb all inputs



	// positive edge detect enabled for portb inputs 
	set_bit(iocbp, IOCBP0);
	set_bit(iocbp, IOCBP1);
	set_bit(iocbp, IOCBP2);
	set_bit(iocbp, IOCBP3);
	set_bit(iocbp, IOCBP4);
	set_bit(iocbp, IOCBP5);
	set_bit(iocbp, IOCBP6);
	set_bit(iocbp, IOCBP7);

   	// negative edge int-on-change disabled	
	clear_bit(iocbn, IOCBN0);
	clear_bit(iocbn, IOCBN1);
	clear_bit(iocbn, IOCBN2);
	clear_bit(iocbn, IOCBN3);
	clear_bit(iocbn, IOCBN4);
	clear_bit(iocbn, IOCBN5);
	clear_bit(iocbn, IOCBN6);
	clear_bit(iocbn, IOCBN7);


	trisc = 00000000b; 	// portc all outputs

}

void main()
{
init_processor();
porta = 0;
portb = 0;

  intcon = (1<<GIE | 1<<IOCIE); // enable interrupts

//Endless loop
while( 1 )
{
	if(flag1)
	{
		led1 = !led1;	//on/off
		flag1 = !flag1; //reset
	}
}//while
}//main

Share this post


Link to post
Share on other sites

The support for the 19XX devices is new to BoostC. It is possible that the IDE debugger does not yet support the IOC features of these devices i.e. +/- edge detection over the any edge detection of other chips.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...