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

📄 main.c

📁 XC164cm GPIO 英飞凌的16位单片机 GPIO 开发的基础程序
💻 C
字号:
//****************************************************************************
// @Module        Project Settings
// @Filename      MAIN.C
// @Project       GPIO.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC164CM-8F20
//
// @Compiler      Keil
//
// @Codegenerator 1.0
//
// @Description   This file contains the project initialization function.
//
//----------------------------------------------------------------------------
// @Date          2007-6-7 10:43:12
//
//****************************************************************************

// USER CODE BEGIN (MAIN_General,1)
/********************************************************************\
** 程序功能: 实现端口P1L外接的8个LED循环采用三种不同的方式移动点亮 **
** 版    本: v1.0                                                  **
** 作    者: lezm   北京乾勤科技                                   **
** 日    期: 2007年6月7日                                          **
\********************************************************************/
// USER CODE END

//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"

// USER CODE BEGIN (MAIN_General,2)

// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************

// USER CODE BEGIN (MAIN_General,3)

// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************

// USER CODE BEGIN (MAIN_General,4)
#define FLASH_LED P1L						//连接LED端口定义
// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************

// USER CODE BEGIN (MAIN_General,5)

// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************

// USER CODE BEGIN (MAIN_General,6)

// USER CODE END


//****************************************************************************
// @Global Variables
//****************************************************************************

// USER CODE BEGIN (MAIN_General,7)
ubyte FlashLed[]={0x18,0x24,0x42,0x81,0x00}; //控制从LED中间向两边移的数组
// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************

// USER CODE BEGIN (MAIN_General,8)

// USER CODE END


//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************

// USER CODE BEGIN (MAIN_General,9)
//*********** 延时函数 ********
void delay(uword x)
{
    uword i;
    while(x--)
    for(i=0;i<60000;i++)
        continue;
}

//********* LED点亮后单个右移 *********
void RightMovLed(void)
{
    uword temp;
    temp=0x40;
    while(temp)
    {
        temp=temp>>1&0x7f;
        FLASH_LED=temp;
        delay(90);
    }
}

//********* LED点亮后单个左右移 *********
void LeftMovLed(void)
{
    uword temp;
    temp=0x01;
    while(temp)
    {
        temp=temp<<1&0xfe;
        FLASH_LED=temp;
        delay(90);
    }
}

//********* 实现两个LED从中间跑两边 *********
void LedFlash(void)
{
    ubyte i=0;
    while(FlashLed[i])
    {
        FLASH_LED=FlashLed[i];
        i++;
        delay(90);
    } 
}

//********* 交叉闪烁 *********
void crossFlash(void)
{
    ubyte i,temp;
    temp=0x55;
    for(i=0;i<10;i++)
    {
        FLASH_LED=temp;
        temp=~temp;
        delay(90);
    }
}

// USER CODE END


//****************************************************************************
// @Function      void MAIN_vInit(void) 
//
//----------------------------------------------------------------------------
// @Description   This function initializes the microcontroller.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2007-6-7
//
//****************************************************************************

// USER CODE BEGIN (Init,1)

// USER CODE END

void MAIN_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  ///  -----------------------------------------------------------------------
  ///  Configuration of the System Clock:
  ///  -----------------------------------------------------------------------
  ///  - VCO clock used, input clock is connected
  ///  - input frequency is 8 MHz
  ///  - VCO output frequency 100 .. 150 MHz
  ///  - system clock is 20 MHz

  MAIN_vUnlockProtecReg();       // unlock write security
  PLLCON         =  0x7814;      // load PLL control register


  //// -----------------------------------------------------------------------
  //// Begin of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------
  ///  All following settings must be set in the start-up file. You can use 
  ///  DAvE's project file (*.dpt) to include this register values into your 
  ///  compiler EDE.

    ///  ---------------------------------------------------------------------
    ///  Initialization of the CPUCON1 Register:
    ///  ---------------------------------------------------------------------
    ///  - space between two vectors is 2 words
    ///  - DISWDT executable until End of Init
    ///  - segmentation is enabled
    ///  - switch context is interruptible
    ///  - branch prediction is enabled
    ///  - zero cycle jump function is enabled

    //// this register must be set in the start-up file
    //// CPUCON1  =  0x0007

    ///  ---------------------------------------------------------------------
    ///  Initialization of the VECSEG Register:
    ///  ---------------------------------------------------------------------
    ///  - start from internal program memory

    //// this register must be set in the start-up file
    //// VECSEG  =  0x00C0

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON0 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON0  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON1 Register:
    ///  ---------------------------------------------------------------------
    ///  clock prescaler for system is fpll / 1
    ///  clock prescaler for PD+ bus is fcpu / 1

    //// this register must be set in the start-up file
    //// SYSCON1  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON3 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON3  =  0x0000

  //// -----------------------------------------------------------------------
  //// End of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------


  //   -----------------------------------------------------------------------
  //   Initialization of the Peripherals:
  //   -----------------------------------------------------------------------

  //   initializes the Parallel Ports
  IO_vInit();

  // USER CODE BEGIN (Init,3)

  // USER CODE END

  //   globally enable interrupts
  PSW_IEN        =  1;          

} //  End of function MAIN_vInit


//****************************************************************************
// @Function      void MAIN_vUnlockProtecReg(void) 
//
//----------------------------------------------------------------------------
// @Description   This function makes it possible to write one protected 
//                register. After calling of this function and write on the 
//                protected register is the security level set to low 
//                protected mode.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2007-6-7
//
//****************************************************************************

// USER CODE BEGIN (UnlockProtecReg,1)

// USER CODE END

void MAIN_vUnlockProtecReg(void)
{
  uword uwPASSWORD;

  if((SCUSLS & 0x1800) == 0x0800)      // if low protected mode
  {

    uwPASSWORD = SCUSLS & 0x00FF;
    uwPASSWORD = (~uwPASSWORD) & 0x00FF;
    SCUSLC = 0x8E00 | uwPASSWORD;      // command 4

  }  // end if low protected mode

  if((SCUSLS & 0x1800) == 0x1800)      // if write protected mode
  {
    SCUSLC = 0xAAAA;                   // command 0
    SCUSLC = 0x5554;                   // command 1

    uwPASSWORD = SCUSLS & 0x00FF;
    uwPASSWORD = (~uwPASSWORD) & 0x00FF;

    SCUSLC = 0x9600 | uwPASSWORD;      // command 2
    SCUSLC = 0x0800;                   // command 3; new PASSWOR is 0x00

    uwPASSWORD = SCUSLS & 0x00FF;
    uwPASSWORD = (~uwPASSWORD) & 0x00FF;
    SCUSLC = 0x8E00 | uwPASSWORD;      // command 4

  }  // end if write protected mode

} //  End of function MAIN_vUnlockProtecReg


//****************************************************************************
// @Function      void main(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the main function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2007-6-7
//
//****************************************************************************

// USER CODE BEGIN (Main,1)

// USER CODE END

void main(void)
{
  // USER CODE BEGIN (Main,2)

  // USER CODE END

  MAIN_vInit();

  // USER CODE BEGIN (Main,4)
while(1)
{
	RightMovLed();
	delay(100);
    LeftMovLed();
	delay(100);
    LedFlash();
	delay(100);
    crossFlash();
	delay(100);
}

  // USER CODE END

} //  End of function main



// USER CODE BEGIN (MAIN_General,10)

// USER CODE END

⌨️ 快捷键说明

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