📄 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: 李仲生
** Created date: 2006-03-26
** Version: 1.00
** Descriptions: 多中断优先级实验
**
**------------------------------------------------------------------------------------------------------
** Modified by: liuyanlong
** Modified date: 2007-08-18
** Version:
** Descriptions: 对代码风格和规范进行校对、调整
**
** Rechecked by : Litiantian
********************************************************************************************************/
#include "config.h"
#define softindex0 (1 << 14) // 0号软中断
#define softindex1 (1 << 15) // 1号软中断
#define softindex2 (1 << 16) // 2号软中断
#define softindex3 (1 << 17) // 3号软中断
#define KEY1 (1 << 12) // KEY1由P0.12控制
#define BEEP (1 << 30) // P3.30控制BEEP,低电平蜂鸣
/**********************************************************************************************************
** 函数名称 :DelayNS
** 函数功能 :长软件延时
** 入口参数 :dly 延时参数,值越大,延时越久
** 出口参数 :无
**********************************************************************************************************/
void DelayNS(uint32 dly)
{
uint32 i;
for ( ; dly > 0; dly--)
for (i = 0; i < 50000; i++);
}
/**********************************************************************************************************
** 函数名称 :IRQ_index0
** 函数功能 :中断服务程序
** 入口参数 :无
** 出口参数 :无
**********************************************************************************************************/
void __irq IRQ_index0(void)
{
FIO3CLR = BEEP;
DelayNS(20);
FIO3SET = BEEP; // 关闭BEEP
DelayNS(100);
DelayNS(300);
VICVectAddr = 0x00; // 通知VIC中断处理结束
VICSoftIntClr = softindex0;
}
/**********************************************************************************************************
** 函数名称 :IRQ_index1
** 函数功能 :中断服务程序
** 入口参数 :无
** 出口参数 :无
**********************************************************************************************************/
void __irq IRQ_index1(void)
{
int x;
for(x = 0; x < 2; x++)
{
FIO3CLR = BEEP;
DelayNS(20);
FIO3SET = BEEP; // 关闭BEEP
DelayNS(100);
}
DelayNS(300);
VICVectAddr = 0x00; // 通知VIC中断处理结束
VICSoftIntClr = softindex1;
}
/**********************************************************************************************************
** 函数名称 :IRQ_index2
** 函数功能 :中断服务程序
** 入口参数 :无
** 出口参数 :无
**********************************************************************************************************/
void __irq IRQ_index2(void)
{
int x;
for (x = 0; x < 3; x++)
{
FIO3CLR = BEEP;
DelayNS(20);
FIO3SET = BEEP; // 关闭BEEP
DelayNS(100);
}
DelayNS(300);
VICVectAddr = 0x00; // 通知VIC中断处理结束
VICSoftIntClr = softindex2;
}
/**********************************************************************************************************
** 函数名称 :IRQ_index3
** 函数功能 :中断服务程序
** 入口参数 :无
** 出口参数 :无
**********************************************************************************************************/
void __irq IRQ_index3(void)
{
int x;
for (x = 0; x < 4; x++)
{
FIO3CLR = BEEP;
DelayNS(20);
FIO3SET = BEEP; // 关闭BEEP
DelayNS(100);
}
DelayNS(300);
VICVectAddr = 0x00; // 通知VIC中断处理结束
VICSoftIntClr = softindex3;
}
/**********************************************************************************************************
** 函数名称 :main
** 函数功能 :多中断优先级实验
** 调试说明 :实验前将KEY1与P0.12相连,若是在外部Flash中调试,可改变各个中断的延时时间。
**********************************************************************************************************/
int main(void)
{
PINSEL0 = 0x00000000;
PINSEL7 = 0x00000000;
FIO3DIR = BEEP; // 设置BEEP控制口输出
FIO3SET = BEEP; // 关闭BEEP
IRQEnable(); // IRQ中断使能
/* 设置中断IRQ */
VICIntSelect = 0x00; // 所有中断通道设置为IRQ中断
VICVectPri14 = 3; // 设置中断优先级3
VICVectAddr14 = (uint32)IRQ_index0; // 设置中断服务程序地址
VICIntEnable = softindex0; // 使能中断
VICVectPri15 = 2; // 设置中断优先级2
VICVectAddr15 = (uint32)IRQ_index1; // 设置中断服务程序地址
VICIntEnable = softindex1; // 使能中断
VICVectPri16 = 1; // 设置中断优先级1
VICVectAddr16 = (uint32)IRQ_index2; // 设置中断服务程序地址
VICIntEnable = softindex2; // 使能中断
VICVectPri17 = 0; // 设置中断优先级0
VICVectAddr17 = (uint32)IRQ_index3; // 设置中断服务程序地址
VICIntEnable = softindex3; // 使能中断
while (1)
{
if ((IO0PIN & KEY1) == 0x00000000)
{
VICSoftInt = (0x0000000f << 14);// 产生软件中断
while ((IO0PIN & KEY1) == 0x00000000);
}
DelayNS(10);
}
return (0);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -