新聞中心

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

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

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

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

本文引用地址:http://www.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ù)功能:長(zhǎng)軟件延時(shí)
** 入口參數(shù):dly延時(shí)控制值,值越大,延時(shí)越長(zhǎng)
** 出口參數(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; //設(shè)置P0口為GPIO功能
IO0DIR=BEEP; //設(shè)置P0.7為輸出

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



關(guān)鍵詞: GPIO輸出蜂鳴器蜂

評(píng)論


技術(shù)專區(qū)

關(guān)閉