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

📄 main.c

📁 飞思卡尔 x12 系列单片机 xgate应用实例
💻 C
字号:
/******************************************************************************
													            Copyright (c) Freescale 2006
File Name    : $RCSfile: main.c,v $

Current Revision :	$Revision: 1.1 $

PURPOSE: Example 3: XGATE Interrupt Pre-Emption                    
                                                                          
                                                                       
DESCRIPTION:  In this example you will configure the MCU to flash a pattern 
              on the LEDs using the CPU and the XGATE.
                                           
                                                                          
UPDATE HISTORY                                                            
REV  AUTHOR    DATE        DESCRIPTION OF CHANGE                          
---  ------    --------    ---------------------                          
1.0                        - initial coding
1.1  b06321    13/12/06    - ported to S12XE

     *******************************************************************
     * File created by: Freescale East Kilbride MCD Applications Group *
     *******************************************************************

******************************************************************************/
#include <hidef.h>            /* common defines and macros */
#include <mc9s12xep100.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xep100"


#include <string.h>
#include "xgate.h"

#define CPU_Request 0x01;
#define XGate_Request 0x81;

/******************************************************************************
Function Name  : SetupXGATE
Engineer       : r32151	
Date           : 01/03/2005
Parameters     : NONE
Returns        : NONE
Notes          : initialize the XGATE vector block
******************************************************************************/
static void SetupXGATE(void) {
  /* initialize the XGATE vector block and
     set the XGVBR register to its start address */
  XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);

  /* enable XGATE mode and interrupts */
  XGMCTL= 0xE1C1; /* XGE | XGFRZ | XGIE */
  /* NB - Bug in Debugger means XGDBG needs to be cleared */
}

/******************************************************************************
Function Name  : main
Engineer       : r32151	
Date           : 01/03/2005
Parameters     : NONE
Returns        : NONE
Notes          : main routine called by Startup.c, 
                  Sets up PORTA as an output and PORTP as input
                  Sets up a PIT every 250ms
                  Allocates events to XGATE and sets their priority
                  Allows PP0 to toggle enabled PITs
******************************************************************************/
void main(void) {
  /* put your own code here */
  SetupXGATE();
  
  /* Set up Port A */
  PORTA = 0x00;
  DDRA  = 0x0F;
  PUCR  = 0x42;
  
  /* Set up Port P */
  DDRP  = 0x00;

  /* Enable PIT channels 0 & 1 */
  PITCFLMT = 0xA0;    /* Enable PIT and Freeze */
  PITCE    = 0x03;    /* Enable channel 0,1,2 */ 
  PITMUX   = 0x00;    /* Use microtimer 0 for all channels */
  PITMTLD0 = 0x01;    /* Microtimer count of 1000 */
  // Want large value of PITLD1 compared with PITLD0 so that when channel 0 is
  
  // enabled it will completely block channel 1
  PITLD0   = 0x01;    /* Channel 0 counter */
  PITLD1   = 0xFFFF;  /* Channel 1 counter */
  
  /* Allocate events to CPU or XGate and prioritize */
  INT_CFADDR  = 0x70;         /* Set interrupt control page to PIT channels */
  INT_CFDATA4 = 0x84;         /* Send PIT1 interrupt to XGate (level 7) */
  INT_CFDATA5 = 0x87;         /* Send PIT0 interrupt to XGate (level 7) */

  //IRQ pin is floating on DEMO boards
  INT_CFADDR = 0xF0;  /* Set interrupt control page to IRQ channels */
  INT_CFDATA1 = 0;    /* Block IRQ from causing interrupt (dynamic alternative to IRQCR bit) */

  // Have to enable interrupts after MPU set or will get XGate ISR before MPU configured
  PITINTE  = 0x01;    /* Enable interrupts on channel 0 */
  
  EnableInterrupts;    
  
  for(;;) 
  {
    // Enable PIT channel 1 interrupt if PP0 is clear.
    while(PTP_PTP0 == 0x00) //while button pressed
    {
       PITINTE = 0x03;// Channels 1 & 0
    }
    PITINTE = 0x02; // Channel 1
  } /* loop forever */
}

⌨️ 快捷键说明

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