test_pwm.c

来自「arm9.rar」· C语言 代码 · 共 74 行

C
74
字号
/****************************************************************************
【文  件  名  称】main.c
【功  能  描  述】三星S3C2410A板demo程序代码
【程  序  版  本】4.0
【创建人及创建日期】icesoar//2002年11月19日19:26
【修改人及修改日期】icesoar//2004-12-8 17:25
****************************************************************************/

//***************************************************************************
#include "def.h"
#include "2410addr.h"
#include "config.h"
#include "board.h"
#include "utils.h"

#define	MaxBeepFreq	20000
#define	MinBeepFreq	20
/****************************************************************************
【功能说明】系统主函数
****************************************************************************/
void TestPwm(void)
{
	U16 BeepFreq = 500;
//	U16 ratio = 50;

   	printf( "S3C2410A PWM Test( Beep ) !\n\n" ) ;

   	printf( "Press +/- to increase/reduce the frequency of beep !\n" ) ;
   	//printf( "Press h/l to increase/reduce the hi-ratio of beep !\n" ) ;
	printf( "Press 'ESC' to Exit this test program !\n\n" );
	
	Beep(BeepFreq, 200);

    while( 1 )
    {
		U8 key;		
		
		key = getch();
		putch( key );

		if( key == '+' )
			if( BeepFreq < 20000 )
				BeepFreq += 100 ;
		if( key == '-' )
			if( BeepFreq > 100 )
				BeepFreq -= 100 ;
		
/*		if( key == 'H' || key == 'h' )
			if( ratio < 100 )
				ratio += 1 ;
		if( key == 'L' || key == 'l' )
			if( ratio > 0 )
				ratio -= 1 ;
*/		
		if( key == ESC_KEY ) break ;
		
		Beep( BeepFreq, 200 ) ;
		//printf( "\tNow beep frequence is %dHz Hi-ratio %d%%\n", BeepFreq, ratio ) ;
		printf( "Now beep frequence is %dHz\n", BeepFreq) ;
	}
	
	printf( "\n" ) ;
}

static char title[] = "蜂鸣器输出实验";
static char tip[]   = "实验由S3C2410A的定时器产生的PWM输出控制蜂鸣器,按+/-键调节PWM的频率,按ESC键返回";

//TestPwmItem在prog_entry.c里被引用
TEST_PROGRAM_ITEM TestPwmItem = {
				(TEST_PROGRAM)TestPwm, 	//入口地址
				title, 					//显示名称
				tip, 					//帮助或提示信息,可为NULL
				1};						//使用printf,puts,putch等函数时在LCD上也显示输出字符(串)

⌨️ 快捷键说明

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