📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: Chenxibing
** Modified date: 2005-01-19
** Version:
** Descriptions: VIC软件中断实验2
**
********************************************************************************************************/
#include "config.h"
#define BEEP 1 << 7 // P0.7控制蜂鸣器
#define SoftInt 30 // 使用的中断号
/*
*********************************************************************************************************
** 函数名称 :DelayNS()
** 函数功能 :长软件延时
** 入口参数 :dly 延时参数,值越大,延时越久
** 出口参数 :无
*********************************************************************************************************
*/
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<50000; i++);
}
/*
*********************************************************************************************************
** 函数名称 :IRQ_SoftInt()
** 函数功能 :软件中断服务程序,取反BEEP控制口。
** 入口参数 :无。
** 出口参数 :无。
*********************************************************************************************************
*/
void __irq IRQ_SoftInt (void)
{
if ((IO0SET & BEEP) == 0) // 读取当前BEEP的控制值
IO0SET = BEEP;
else
IO0CLR = BEEP;
VICSoftIntClear = 1 << SoftInt; // 清除软中断
VICVectAddr = 0; // 向量中断结束
}
/*
*********************************************************************************************************
** 函数名称 :main()
** 函数功能 :初始化外部中断为非向量中断,低电平触发,然后等待中断。
** 调试说明 :在Startup.s文件中使能IRQ中断(清零CPSR中的I位)。
*********************************************************************************************************
*/
int main (void)
{
uint32 i;
PINSEL1 = 0x00000001; // 设置管脚连接,P0.16为EINT0
IO0DIR = BEEP; // 设置BEEP控制口为输出,其余输入
IO0SET = BEEP;
IRQEnable(); // IRQ中断使能
/* 打开EINT0中断(使用向量中断) */
VICIntSelect = 0x00000000; // 设置所有中断分配为IRQ中断
VICVectCntl0 = 0x20 | SoftInt; // 分配外部中断0到向量中断0
VICVectAddr0 = (uint32)IRQ_SoftInt; // 设置中断服务程序地址
VICIntEnable = 1 << SoftInt; // 使能EINT0中断
/* 强制产生10次软件中断 */
for (i=0; i<10; i++)
{
VICSoftInt = 1 << SoftInt; // 产生软件中断
DelayNS(50);
}
while (1);
return (0);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -