Jose Rodriguez

MC9S12DG256B Timer Interrupt

Discussion created by Jose Rodriguez on Dec 2, 2010
Latest reply on Dec 15, 2010 by P Manasa

Hi, I'm a learning student currently working with the MC9S12DG256B in codewarrior, and I have a few questions in regards of interrupts in C.

 Down below there is a program I found out that basically use the timer overflow to interrupt and increment count everytime it sees an overflow. The main problem is the program hangs up after 65536, I wanna know if there is something else that I need to configure to get this working.

THX

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */


#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"


volatile unsigned int count;
void main(void) {
  /* put your own code here */
 
  TSCR1=0X80;//enable timer
  TSCR2=0x80;  //select prescler bus
  TFLG2=0x80;// clear timer flag
 
  EnableInterrupts;
 
  for(;:smileywink:
  {
 
  } /* wait forever */
}

#pragma CODE_SEG NON_BANKED

interrupt void _Timerovf(void)
{


 TFLG2 = 0x80;// clear the interrupt flag
 
 count++; //increment counter
   
}   
#pragma CODE_SEG DEFAULT

Outcomes