⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basic.c

📁 Freescale HCS12 系列嵌套中断源码
💻 C
字号:
/******************************************************************************
* 		                                            COPYRIGHT (c) MOTOROLA 2003   
* FILE NAME: basic.c                                                      
*                                                                           
* PURPOSE: nested interrupt demonstration program 											 
*                                                                           
*******************************************************************************
*******************************************************************************  
**  THIS CODE IS ONLY INTENDED AS AN EXAMPLE FOR THE METROWERKS COMPILER AND **  
**      THE HCS12 EVB AND HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST.       **  
**  IT IS PROVIDED 'AS SEEN' WITH NO GUARANTEES AND NO PROMISE OF SUPPORT.   **  
*******************************************************************************  
*******************************************************************************
*                                                                           
* DOCUMENTATION SOURCE: EKB Applications                                         
*                                                                           
* TARGET DEVICE: MC9S12DP256                                               
*                                                                                                                                      
* COMPILER: Metrowerks                            VERSION: HC12_V3.0                    
*                                                                                                                                                
* AUTHOR: G.More/D.Malik       LOCATION: EKB      LAST EDIT DATE: 1/10/03
*                                                                         
* UPDATE HISTORY                                                         
* REV      AUTHOR       DATE       DESCRIPTION OF CHANGE                  
* ---      ------      ---------   ---------------------                 
* 1.0      G.More  	   28/9/03	   initial coding                       
* 2.0      D.Malik     1/10/03     modifications for pre-processor based fns.
*
******************************************************************************/                                                                        
/*===========================================================================*/
/* Motorola reserves the right to make changes without further notice to any */
/* product herein to improve reliability, function, or design. Motorola does */
/* not assume any  liability arising  out  of the  application or use of any */
/* product,  circuit, or software described herein;  neither  does it convey */
/* any license under its patent rights  nor the  rights of others.  Motorola */
/* products are not designed, intended,  or authorized for use as components */
/* in  systems  intended  for  surgical  implant  into  the  body, or  other */
/* applications intended to support life, or  for any  other application  in */
/* which the failure of the Motorola product  could create a situation where */
/* personal injury or death may occur. Should Buyer purchase or use Motorola */
/* products for any such intended  or unauthorized  application, Buyer shall */
/* indemnify and  hold  Motorola  and its officers, employees, subsidiaries, */
/* affiliates,  and distributors harmless against all claims costs, damages, */
/* and expenses, and reasonable  attorney  fees arising  out of, directly or */
/* indirectly,  any claim of personal injury  or death  associated with such */
/* unintended or unauthorized use, even if such claim alleges that  Motorola */
/* was negligent regarding the  design  or manufacture of the part. Motorola */
/* and the Motorola logo* are registered trademarks of Motorola Ltd.         */
/*****************************************************************************/

#include "nested_ints_defs.h"
#include "nested_ints.h"

/* include files */
#include "basic.h"

/******************************************************************************
Function Name	:	main
Engineer		:	G.More
Date			:	1/10/03
Parameters		:	NONE
Returns			:	NONE
Notes			:	main routine 
******************************************************************************/
void 
main(void) 
{  	
	Regs.ddrb.byte = 0x07;	/* set channels 0,1 and 2 of port B to outputs */
	Regs.portb.byte = 0x00;	/* clear channels 0,1 and 2 of port B */

	EnableInterrupts;		/* CLI instruction */
	
	Timer.tios.byte = (IOS2|IOS1|IOS0);	/* set channels 0,1 and 2 to output compare */
	
	/* Configuration 1 - Interrupt 0,1 and 2 simultaneously */
	Timer.tc[0].word = 1;	    /* set output compare value - channel 0 */
	Timer.tc[1].word = 1;		/* set output compare value - channel 1 */
	Timer.tc[2].word = 1;		/* set output compare value - channel 2 */
	
	/* Configuration 2 - Interrupt order = 0 then 1 then 2 */
	//Timer.tc[0].word = 1;		    /* set output compare value - channel 0 */
	//Timer.tc[1].word = 2000;		/* set output compare value - channel 1 */
	//Timer.tc[2].word = 4000;		/* set output compare value - channel 2 */
	  
	Timer.tctl2.byte = (OL2|OL1|OL0);	/* toggle timer pin on compare */
	  	
   	Timer.tscr2.byte = (PR2);  		/* set timer prescaler to divide by 16 */
	
	Timer.tie.byte = (C2I|C1I|C0I);	/* enable channel 0, 1 and 2 interrupts */
		  							
	Timer.tscr1.byte = (TEN);		/* start the master timer */
	
	while(1)
	{
	}
}

/******************************************************************************
Function Name	:	Delay
Engineer		:	M.Gallop
Date			:	02/06/00
Parameters		:	int delayTime
Returns			:	NONE
Notes			:	simple software delay dependent on CPU clock frequency and
					compile strategy 
******************************************************************************/
void 
Delay(int delayTime)					
{
  	int x;	/* outer loop counter */
  	char y;	/* inner loop counter */

  	for (x=0; x<delayTime; x++)
  	{	
  		for (y=0; y<100; y++); 
	}
}  
	
/*****************************************************************************/
/* Start of interrupt service routines  */
/* placed into non-banked memory segment as vectors are only 2 bytes */

#pragma CODE_SEG NON_BANKED	
/******************************************************************************
Function Name	:	_Timer0ISR
Engineer		:	G.More	
Date			:	25/09/03
Parameters		:	NONE
Returns			:	NONE
Notes			:	Interrupt service routine for timer channel 0. Toggles PB0. 
******************************************************************************/
#pragma TRAP_PROC
void 
_Timer0ISR( void )
{
	static tU08 previousPriority;	/* local variable to store priority level to allow return */

	INT8_LEVEL_SET(previousPriority);	/* store current priority level before changing it */
	
	Timer.tflg1.byte = 0x01;	/* negate interrupt flag */
	
    Regs.portb.bit.ptb0 = 1;	/* set flag to indicate start of ISR */
    Delay(100);					/* wait a while */
    Regs.portb.bit.ptb0 = 0; 	/* clear flag to indicate end of ISR */    
    
    int_level_restore(previousPriority);  /* returns priority level to original level */                          
}

/******************************************************************************
Function Name	:	_Timer1ISR
Engineer		:	G.More	
Date			:	25/09/03
Parameters		:	NONE
Returns			:	NONE
Notes			:	Interrupt service routine for timer channel 1. Toggles PB1.  
******************************************************************************/
#pragma TRAP_PROC
void 
_Timer1ISR( void )
{
	static tU08 previousPriority;	/* local variable to store priority level to allow return */

	INT9_LEVEL_SET(previousPriority);	/* store current priority level before changing it */
    
    Timer.tflg1.byte = 0x02;	/* negate interrupt flag */
    
    Regs.portb.bit.ptb1 = 1;	/* set flag to indicate start of ISR */
    Delay(100);					/* wait a while */
    Regs.portb.bit.ptb1 = 0; 	/* clear flag to indicate end of ISR */          
    
    int_level_restore(previousPriority); /* returns priority level to original level */                   
}

/******************************************************************************
Function Name	:	_Timer2ISR
Engineer		:	G.More	
Date			:	25/09/03
Parameters		:	NONE
Returns			:	NONE
Notes			:	Interrupt service routine for timer channel 2. Toggles PB2.
******************************************************************************/
#pragma TRAP_PROC
void 
_Timer2ISR( void )
{
	//static tU08 previousPriority;	/* local variable to store priority level to allow return */

	//INT10_LEVEL_SET(previousPriority);	/* store current priority level before changing it */
	
	Timer.tflg1.byte = 0x04;	/* negate interrupt flag */
	
	Regs.portb.bit.ptb2 = 1; 	/* set flag to indicate start of ISR */
    Delay(100);					/* wait a while */
    Regs.portb.bit.ptb2 = 0; 	/* clear flag to indicate end of ISR */          

    //int_level_restore(previousPriority); /* returns priority level to original level */ 
}

/******************************************************************************
Function Name	:	_dummyISR
Engineer		:	M.Gallop	
Date			:	25/07/01
Parameters		:	NONE
Returns			:	NONE
Notes			:	Interrupt service routine for unused interrupt vectors. 
******************************************************************************/
#pragma TRAP_PROC
void 
_dummyISR( void )
{
		/* endless cycle */
    while(1)
	{;
	}                                 
}

/* End of interrupt service routines  */
/* reset code segment to default */
#pragma CODE_SEG DEFAULT

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -