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.

pic18f4550 timer 2 interrupt

Status
Not open for further replies.

john blue

Member
Hi,

I am trying to use timer 2 interrupt, but the tm2if flag did not set. Anyone can help to check whether whats wrong with my code? I am using Hi Tech C. Thanks

Code:
#include <htc.h>
#include <stdio.h>
#include "isr.h"
#define USE_OR_MASKS 
#include "plib.h"

//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);



void main(){

while(1){

	TRISD7 = 1;
	TRISD6 = 0;
	
	TRISD0 = 0;
	TRISD1 = 0;
	TRISD2 = 0; 	
	TRISD5 = 0;

	//.5mA,5mA,50mA
	RD0 = pulse;
	RD1 = 1;
	RD2 = 1;

	RD5 = 0;
	
 	CMCON = 0x01;   //Outputs' Mode

  	TRISA0 = 1;    // Configure as input pin for negative input of Comparator 1
    TRISA3 = 1;    // Configure as input pin for positive input of Comparator 1
//	TRISA4 = 0;    // Output
	TRISA4 = 1;    // Input for proteus sim
	TRISA1 = 1;

	RA4 = C1OUT;
     
	//Interrupt enable
	IPEN = 1;
	GIEH=1;																	
		
	PEIE=1;

	TMR2IF = 0;
	TMR2IE = 1; 
	ei();


	T2CON = 56;
	TMR2ON = 1;
	PR2 = 246;

	
  T2CKPS0 = 0;
  T2CKPS1 = 0;
 
 T2OUTPS0 = 0;
 T2OUTPS1 = 1;
 T2OUTPS2 = 1;
 T2OUTPS3 = 1;
	TMR2IP = 1;


	//startup
	if(!RD7){
	RD6 = 1;
	}
	
}

	
}
 
As you haven't posted your ISR code, it's difficult to comment.

My guess would be that the code may not even be running due to the wrong config values. Had you used the Microchip labels, instead of silly hex values, I would have been able to check them.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top