新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > GPIO輸出---控制蜂鳴器蜂鳴

GPIO輸出---控制蜂鳴器蜂鳴

作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
/*****************************Copyright (c)******************************

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

本文引用地址:http://2s4d.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控制蜂鳴器,低電平蜂鳴

/*************************************************************************
** 函數(shù)名稱:DelayNS()
** 函數(shù)功能:長軟件延時
** 入口參數(shù):dly延時控制值,值越大,延時越長
** 出口參數(shù):無
*************************************************************************/

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


/*************************************************************************
** 函數(shù)名稱:main()
** 函數(shù)功能:用P0.7控制BEEP,讓蜂鳴器蜂鳴
** 調(diào)試說明:需將跳線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
******************************************************************************/



評論


技術專區(qū)

關閉
×

Digikey let's do
· 2025年第1期限时报名开启,5月8日截止
· Digikey助力,提供一站式免费器件支持
· 跟大佬一起 【DIY 功率监测与控制系统】