⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beep.bak

📁 自己设计的pic单片机开发板源程序和说明书(内有原理图)支持pic16系列28脚和40脚器件。串口输出信息。4个LED数码管驱动;4个LED驱动;4个按键驱动;1个RS232接口;1个RS485接口;
💻 BAK
字号:
/*#include "..\demo\def.h"
#include "..\demo\demo.h"
#include "..\demo\PIC_EVB.h"*/
void set_pwm(int16 fpwm)
{
int16 duty;
int8	pr2_val,t2div= 16;
	pr2_val = (MCLK/fpwm/t2div)>>2 - 1;	//        mclk/4/fpwm/t2div-1
	duty =  (pr2_val+1)<<1;				//50% duty.
								//ccsc defined:  duty = Tduty/(t2div*Tclk)
								//Tperiod = Tclk*4*t2div*(pr2+1);
								//pwm is 50%,so Tduty = Tperiod / 2
								//so duty = Tperiod/2/t2div/Tclk=2*(pr2+1)

	setup_timer_2(T2_DIV_BY_16, pr2_val, 1);
	set_pwm2_duty(duty);
}


int8 Test_beep()
{
int16 duty,fpwm;
int8	pr2_val,t2div= 16;
int8 i;
	fpwm = 1000;			//1000hz.
	set_pwm(fpwm);
	setup_ccp2(CCP_PWM);
//	set_tris_c(0xfd);
	output_low(beep);
	while(TRUE)
	{
		i = getc();
		if(i == '=')
		{
			fpwm+=100;
			if(fpwm<20000)
			{
				set_pwm(fpwm);
				printf("%d\n",fpwm);
			}
		}
		else if(i == '-')
		{
			fpwm-=100;
			if(fpwm>500)
			{
				set_pwm(fpwm);
				printf("%d\n",fpwm);
			}
		}
		else if(i == ESC_KEY)
		{
			input(beep);
			return(0);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -