📄 pwm_0_9.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -