📄 pwm_example.c
字号:
/***********************************************************************
* $Workfile: pwm_example.c $
* $Revision: 1.0 $
* $Author: WellsK $
* $Date: Oct 15 2003 16:46:54 $
*
* Project: PWM driver example
*
* Description:
* A simple PWM driver example.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/examples/pwm/pwm_example.c-arc $
*
* Rev 1.0 Oct 15 2003 16:46:54 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "abl_types.h"
#include "lh7a404_pwm_driver.h"
/* PWM device handle */
STATIC INT_32 pwmdev;
/***********************************************************************
*
* Function: c_entry
*
* Purpose: PWM example
*
* Processing:
* Sets up PWM0 for an output of 3KHz. The duty cycle will slowly
* be adjusted from 1 to 100%.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Always returns 1
*
* Notes:
* To examine the output, connect an oscilloscope to the PWM0
* pin on the SDK expansion connector.
*
**********************************************************************/
int c_entry(void)
{
INT_32 idx, del;
/* Open PWM0 */
if ((pwmdev = pwm_open(PWM, 0)) == 0x00000000)
{
return 0;
}
/* Setup PWM2 for a 3KHz clock with a 50% duty cycles */
pwm_ioctl(pwmdev, PWM2_SETFREQ, 3000);
pwm_ioctl(pwmdev, PWM2_SETDUTY, 50);
pwm_ioctl(pwmdev, PWM2_ENABLE, 1);
for (idx = 1; idx < 100; idx++)
{
pwm_ioctl(pwmdev, PWM2_SETDUTY, idx);
for (del = 0; del < 200000; del++);
}
/* Close PWM */
pwm_close(pwmdev);
return 1;
}
#ifndef __GNUC__
/* With ARM and GHS toolsets, the entry point is main() - this will
allow the linker to generate wrapper code to setup stacks, allocate
heap area, and initialize and copy code and data segments. For GNU
toolsets, the entry point is through __start() in the crt0_gnu.asm
file, and that startup code will setup stacks and data */
int main(void)
{
return c_entry();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -