📄 pwm.c
字号:
/*********************************************************************************************
* File: pwm.c
* Author: Embest z.j.zheng
* Desc: test pwm function through buzzer
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include <board.h>
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(int dly)
{
int i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: pwm_Init
* func: init the pwm
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void pwm_Init(void)
{
AT91F_PWMC_InterruptDisable(AT91C_BASE_PWMC,AT91C_PWMC_CHID0); //Disable PWM Interrupt
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC,0,
(AT91C_PWMC_CPRE_MCK | AT91C_PWMC_CALG | AT91C_PWMC_CPOL | AT91C_PWMC_CPD),
AT91C_PWMC_CPRD,AT91C_PWMC_CDTY);
AT91F_PWMC_StartChannel(AT91C_BASE_PWMC,AT91C_PWMC_CHID0); //Enable channel
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int Main(void)
{
unsigned int i;
//enable the clock of the PIO
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
AT91F_PWMC_CH0_CfgPIO();
AT91F_PWMC_CfgPMC();
AT91F_PIO_CfgInput( AT91C_BASE_PIOA, SW1_MASK ) ;
pwm_Init();
do
{
i= AT91F_PIO_GetInput(AT91C_BASE_PIOA);
// detect whether button1 or button1 pushed down
if( (i&SW1) == 0 ) AT91F_PWMC_StopChannel(AT91C_BASE_PWMC,AT91C_PWMC_CHID0);
else if( (i&SW2) == 0 ) AT91F_PWMC_StartChannel(AT91C_BASE_PWMC,AT91C_PWMC_CHID0);
} while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -