📄 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: LinEnqiang
** Created date: 2006-12-1
** Version: 1.0
** Descriptions: softintertupt
**
**--------------------------------------------------------------------------------------------------------
** Modified by: wankai
** Modified date: 2008-07-09
** Version:
** Descriptions: 对代码风格和规范进行校对、调整
**
** Rechecked by : Litiantian
*********************************************************************************************************/
#include "config.h"
#define softindex0 (1 << 0) /* 0号软中断 */
#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
** 函数功能 :中断服务程序,取反BEEP控制口
** 入口参数 :无
** 出口参数 :无
*********************************************************************************************************/
void __irq IRQ_index0(void)
{
if ((FIO3SET & BEEP) == 0) {
FIO3SET = BEEP; /* 关闭BEEP */
}
else {
FIO3CLR = BEEP;
}
T1IR = 0x01; /* 清除中断标志 */
VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
VICSoftIntClr = softindex0;
}
/*********************************************************************************************************
** 函数名称 :main
** 函数功能 :软件中断主函数
** 调试说明 : 实验前分别将P0.12与KEY1、BEEP与P3.30相连
*********************************************************************************************************/
int main(void)
{
PINSEL0 = 0x00000000;
PINSEL7 = 0x00000000;
FIO3DIR = BEEP; /* 设置BEEP控制口输出 */
FIO3SET = BEEP; /* 关闭BEEP */
IRQEnable(); /* IRQ中断使能 */
/* 设置中断IRQ */
VICIntSelect = 0x00; /* 所有中断通道设置为IRQ中断*/
VICVectPri0 = 0; /* 设置中断优先级 */
VICVectAddr0 = (uint32)IRQ_index0; /* 设置中断服务程序地址 */
VICIntEnable = softindex0; /* 使能中断 */
while (1) {
if ((IO0PIN & KEY1) == 0x00000000) {
VICSoftInt = softindex0; /* 产生软件中断 */
while ((IO0PIN & KEY1) == 0x00000000);
}
DelayNS(10);
}
return (0);
}
/*********************************************************************************************************
** End Of File
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -