×
单片机 > 单片机程序设计 > 详情

PIC单片机-蜂鸣器使用示例

发布时间:2020-06-01 发布时间:
|

PIC中档单片机蜂鸣器原理图:

使用示例:

/*******************************************************************************
* 跳线接法:短接P2的2、3
* 功能描述:无源蜂鸣器发声
*******************************************************************************/
#include 
#include 
 
#define uint8 unsigned char
#define uint16 unsigned int
 
__CONFIG(WDTDIS & LVPDIS & HS & PWRTDIS & BORDIS);//设置配置位
//WDTDIS:disable watchdog timer
//LVPDIS:low voltage programming disabled
//HS:high speed crystal/resonator
//PWRTDIS:disable power up timer
//BORDIS:disable brown out reset
 
/***************************声明函数*******************************************/
 
void DelayUS(uint8 delay);
 
/*******************************************************************************
* 函 数 名: DelayUS(uint8 delay)
* 函数功能: 微秒延时   for 20MHZ
* 入口参数: delay
* 返    回: 无
*******************************************************************************/
 
void DelayUS(uint8 delay)
{
	while(--delay);
}
 
/******************************************************************************
* 函 数 名: mian(void)
* 函数功能: 驱动无源蜂鸣器发声
* 入口参数: 无
* 返    回: 无
*******************************************************************************/
 
void main(void)
{	
	ADCON1 = 0x86;	//PORTA设置为数字IO口
	TRISA0 = 0;		//RA0设置为输出模式
	while(1)
	{	
		RA0 = 1;
		DelayUS(400);
		RA0 = 0;
		DelayUS(400);					    	
	}
}


关键字:PIC单片机  蜂鸣器

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
STM32中断向量表的位置.重定向