pwm_0_9.c
来自「ti-Chipcon CC1010 1G以下Soc应用开发源码实例。包括rf,p」· C语言 代码 · 共 78 行
C
78 行
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 EXAMPLE PROGRAM *
* *** + + *** PWM *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* Demonstrates use of the timer module as a PWM source. Uses: *
* - PWM2_SET_PERIOD, PWM2_SET_DUTY_CYCLE macros *
* - various other HAL functions and macros *
* *
*****************************************************************************
* Author: TEL/ARR *
*****************************************************************************
* Revision history: *
* 1.0 2002/04/26 First Public Release *
* *
* $Log: pwm_0_9.C,v $
* Revision 1.1 2002/10/14 09:45:07 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>
int duty_cycle = 128;
int main(){
// Disable watchdog timer
WDT_ENABLE(FALSE);
// All I/Os are inputs after reset. Make I/Os connected to LEDs outputs
RLED=YLED=GLED=BLED=LED_OFF;
RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);
// Switch to 32kHz clock first
X32_INPUT_SOURCE(X32_USING_CRYSTAL);
X32_ENABLE(TRUE);
halWait(250, CC1010EB_CLKFREQ);
halWait(250, CC1010EB_CLKFREQ);
MAIN_CLOCK_SET_SOURCE(CLOCK_X32);
XOSC_ENABLE(FALSE);
// Configure timer 2 as a PWM timer, max timeout interval
halConfigTimer23(TIMER2 | TIMER23_PWM, 0, CC1010EB_CLKFREQ);
PWM2_SET_PERIOD(62); // approx 1/2 second
PWM2_SET_DUTY_CYCLE(duty_cycle);
TIMER2_RUN(TRUE);
// infinite loop
while(1) {
// read inputbutton
if (SW2_PRESSED) { // button pushed - increment duty cycle
duty_cycle+=8;
// check that dutycycle is a valid number
if (duty_cycle>256)
duty_cycle = 0;
} else if (SW3_PRESSED) { // button pushed - decrement
duty_cycle-=8;
// check that dutycycle is a valid number
if (duty_cycle<0)
duty_cycle = 256;
} // end if
PWM2_SET_DUTY_CYCLE(duty_cycle);
}
} // end main
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?