第一个程序 beep








/****************************************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: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: Chenxibing
** Modified date: 2006-05-12
** Version: V1.0.1
** Descriptions: 在DeviceARM3000上运行的第一个程序。
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

#include "config.h"

// 定义蜂鸣器控制口
#define     BEEP     (1<<10)     /* GPH10口 */
#define     BEEP_MASK     (~BEEP)


/*********************************************************************************************************
** Function name:  DelayNS
** Descriptions 长软件延时。
**               延时时间与系统时钟有关。
** Input dly 延时参数,值越大,延时越久
** Output
** Created by Chenxibing
** Created Date : 2006-05-12 
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  DelayNS(uint32  dly)
{  
uint32  i;

    for(; dly>0; dly--) 
       for(i=0; i<50000; i++);
}


/*********************************************************************************************************
** Function name: main()
** Descriptions 在DeviceARM3000(底板为MagicARM2200)上运行的第一个程序,控制蜂鸣器周期性鸣叫。          
** Input
** Output 系统返回值0
** Created by Chenxibing
** Created Date 2006-05-12 
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int  main(void)
{
    // 初始化I/O
     rGPHCON = (rGPHCON & (~(0x03<<20))) | (0x01<<20);   // rGPHCON[21:20] = 01b,设置GPH10为GPIO输出模式
    //对控制寄存器  数据寄存器的赋值采用移位和宏赋值
    // 控制蜂鸣器周期性鸣叫
    while(1)
    {
     rGPHDAT = rGPHDAT & BEEP_MASK;     // BEEP = 0,蜂鸣器鸣叫
    DelayNS(30);
     rGPHDAT = rGPHDAT | BEEP;     // BEEP = 1,停止蜂鸣 
     DelayNS(80);
    }  
    
    return(0);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值