📄 beep.c
字号:
#include "def.h"
#include "2410addr.h"
void Beep(U32 freq, U32 ms)
{
rGPBCON &= ~3; //set GPB0 as tout0, pwm output
rGPBCON |= 2;
rTCFG0 &= ~0xff; //与背光共享一个预分频器
rTCFG0 |= 0; //prescaler = 0 + 1
rTCFG1 &= ~0xf;
rTCFG1 |= 3; //mux = 1/16,它跟prescaler决定定时器的频率
rTCNTB0 = (FCLK>>4)/freq;
rTCMPB0 = rTCNTB0>>2; // 分频比为1:3
rTCON &= ~0x1f;
rTCON |= 0xb; //disable deadzone, auto-reload, inv-off, updateTCNTB0&TCMPB0, start timer 0
//启动timer0后就输出一定频率的脉冲,直到stop beep
rTCON &= ~2; //clear manual update bit
Delay(10*ms);
rGPBCON &= ~3; //set GPB0 as output, stop beep
//rGPBCON |= 1;
//rGPBDAT &= ~1;
}
void TestPwm(void)
{
U16 BeepFreq = 500;
printf( "S3C2410A PWM Test( Beep ) !\n\n" ) ;
printf( "Press +/- to increase/reduce the frequency 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 == 'q') break;
Beep( BeepFreq, 200 ) ;
//printf( "\tNow beep frequence is %dHz Hi-ratio %d%%\n", BeepFreq,ratio ) ;
printf( "\nNow beep frequence is %dHz\n", BeepFreq) ;
}
printf( "\n the end \n" ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -