.c文件
#include <ioCC2540.h>
#include "PWM.h"
#ifndef BV
#define BV(n) (1 << (n))
#endif
/******************************************************************************
name: T1_PWM_Init
introduce: 定时器1输出PWM的初始化
parameter: none
return: none
author: neha
changetime: 2018.6.25
******************************************************************************/
void T1_PWM_Init(void)
{
P1DIR |= BV(0);
P1SEL |= BV(0); //P1.0设置为外设I/O口:定时器1通道2
PERCFG |= BV(6); //定时器1为外设位置2(P1.0)
P2SEL &= ~BV(4); //优先级控制:定时器1优先
T1CTL |= 0x02; //1分频,从0x0000到T1CC0反复计数。
T1CCTL2 = 0x34; //定时器1通道2配置为比较输出,当等于T1CC0时设置,当等于T1CC2时清楚
T1CC0L = 32%256; //定时器1通道0捕获/比较值低位
T1CC0H = 32/256; //定时器1通道0捕获/比较值高位
T1CC2L = 10%256; //定时器1通道2捕获/比较值低位
T1CC2H = 10/256; //定时器1通道2捕获/比较值高位
}
.h文件
#ifndef PWM_H
#define PWM_H
#ifndef U8
typedef unsigned char uint8;
#endif
#ifndef U16
typedef unsigned short uint16;
#endif
extern void T1_PWM_Init(void);
#endif