speek.cpp

来自「其于ARM的USB操作,控制芯片为CH375实现操作.以及其他功能.包括AC,串」· C++ 代码 · 共 106 行

CPP
106
字号
#include "Speek.h"
#include "ucos_ii.h"

CSpeek::CSpeek()
{
	bOn = FALSE;
	iFreq = 2500;
}

CSpeek::~CSpeek()
{
}

void CSpeek::Init()
{
	#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
	OS_CPU_SR  cpu_sr;
	#endif
	U32 temp;
	OS_ENTER_CRITICAL();
	//关闭输出
	temp = rTCON;
	temp &= ~(0XF<<8);
	temp |= (0xe<<8);
	rTCON = temp;

	//预分频器 11M
	temp = rTCFG0;
	temp &= ~(0XFF);
	temp |= 5;
	rTCFG0 = temp;
	//时钟选择
	temp = rTCFG1;
	temp &= ~(0xf<<4);
	rTCFG1 = temp;
	
	//设置成PWM输出
	temp = rPCONE;
	temp &= ~(3<<8);
	temp |= (2<<8);
	rPCONE = temp;
	
	OS_EXIT_CRITICAL();
}

void CSpeek::OpenSpeek()
{
	if( !bOn )
	{
		bOn = TRUE;
	#ifdef ARM
		#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
		OS_CPU_SR  cpu_sr;
		#endif
		U32 freq;
		freq = iFreq;
		//计算输出频率
		if( freq == 0 )
		{
			freq = 0;
		}
		else
		{
			freq = (5500000/freq);
		}
		if( freq > 0xffff )
		{
			freq = 0xffff;
		}
		//freq = 0xffff - freq;

		OS_ENTER_CRITICAL();

		rTCNTB1 = freq;
		rTCMPB1	= freq/2;
		//打开输出
		U32 temp;
		temp = rTCON;
		temp &= ~( 0xf << 8 );
		temp |= ( 0x0d << 8 );
		rTCON = temp;
		OS_EXIT_CRITICAL();
	#endif
	}
}

void CSpeek::CloseSpeek()
{
	if( bOn )
	{
		bOn = FALSE;
	#ifdef ARM
		#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
		OS_CPU_SR  cpu_sr;
		#endif

		OS_ENTER_CRITICAL();
		U32 temp;
		temp = rTCON;
		temp &= ~( 0xf << 8 );
		temp |= ( 0x0e << 8 );
		rTCON = temp;
		OS_EXIT_CRITICAL();
	#endif
	}
}

⌨️ 快捷键说明

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