2410BEEP.c
资源名称:arm_exam.rar [点击查看]
上传用户:mhstny
上传日期:2022-08-05
资源大小:793k
文件大小:1k
源码类别:
微处理器开发
开发平台:
Unix_Linux
- #include "2410addr.h"
- #include "2410lib.h"
- #include "def.h"
- /****************************************************************************
- 【功能说明】蜂鸣器PWM测试
- ****************************************************************************/
- void Buzzer_Freq_Set( U32 freq )
- {
- rGPBCON = rGPBCON & ~(3<<0)|(1<<1);//set GPB0 as tout0, pwm output
- rTCFG0 = rTCFG0 & ~0xff|15; //prescaler = 15
- rTCFG1 = rTCFG1 & ~0xf|2;//divider = 1/8
- rTCNTB0 = (PCLK>>7)/freq;//rTCNTB0=PCLK/{(prescaler+1) * divider *freq}
- rTCMPB0 = rTCNTB0>>1; //占空比50%
- //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
- rTCON = rTCON & ~0x1f|(0<<4)|(1<<3)|(0<<2)|(1<<1)|(1);
- rTCON &= ~(1<<1); //clear manual update bit
- }
- void Buzzer_Stop( void )
- {
- rGPBCON &= ~12; //set GPB1 as output
- rGPBCON |= 4;
- rGPBDAT &= ~1;
- }
- void Buzzer_PWM_Run( void )
- {
- U16 freq = 2000 ;
- Buzzer_Freq_Set( freq ) ;
- }