新闻中心

EEPW首页>嵌入式系统>设计应用> GPIO输出---控制蜂鸣器蜂鸣

GPIO输出---控制蜂鸣器蜂鸣

作者: 时间:2016-11-10 来源:网络 收藏
/*****************************Copyright (c)******************************

**--------------File Info--------------------------------------------------

本文引用地址://m.amcfsurvey.com/article/201611/317404.htm

** File name:main.c
** Last modified Date: 2011-04-09
** Last Version:1.0
** Descriptions:The main() function example template
**-------------------------------------------------------------------------
** Created by:lxliu
** Created date:2011-04-09
** Version:1.0
**************************************************************************/
#include "config.h"

#define BEEP 1<<7 //P0.7控制蜂鸣器,低电平蜂鸣

/*************************************************************************
** 函数名称:DelayNS()
** 函数功能:长软件延时
** 入口参数:dly延时控制值,值越大,延时越长
** 出口参数:无
*************************************************************************/

void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}


/*************************************************************************
** 函数名称:main()
** 函数功能:用P0.7控制BEEP,让蜂鸣器蜂鸣
** 调试说明:需将跳线JP11和BEEP短接
*************************************************************************/

int main (void)
{
PINSEL0=0x00000000; //设置P0口为GPIO功能
IO0DIR=BEEP; //设置P0.7为输出

while(1)
{
IO0SET=BEEP; //蜂鸣器停止蜂鸣
DelayNS(10); //延时
IO0CLR=BEEP; //蜂鸣器蜂鸣
DelayNS(100);//延时
}
return 0;
}
/*****************************************************************************
** End Of File
******************************************************************************/



评论


技术专区

关闭