TI中文支持网
TI专业的中文技术问题搜集分享网站

BLE ,2540引出4路PWM,大神请进

HI ALL:

我想在手机上输入5个数据,然后更新PWM占空比,PWM引脚接LED,我这样的设置却是LED在间隔闪。

求指导,我的程序如下,如何做到我输入0x00~0xff  LED的亮度改变。或有偿+q 474336933备注

void pwm_init(void)
{
P0DIR |= (1<<3) | (1<<4) | (1<<5) | (1<<6); // 0x1C; //0x18; // Data direction OUT for the PWM pins
P0SEL |= (1<<3) | (1<<4) | (1<<5) | (1<<6); //0x18; // Choose peripheral mode for PWM pins
PERCFG |= 0x03; // Move USART1&2 to alternate2 location so that T1 is visible
T1CTL = 0x01 << 2; //从零到T1CC0计数
T1CCTL1 = (0x04 << 3) | (0x01 << 2); //在向上比较清除输出,在0设置。否则在比较清除输出,在0设置;0x01左移两位的意思是:比较模式
T1CCTL2 = (0x04 << 3) | (0x01 << 2);
T1CCTL3 = (0x04 << 3) | (0x01 << 2);
T1CCTL4 = (0x04 << 3) | (0x01 << 2);
T1CC0L = 0x0FA0 & 0xFF; //pwm频率初始化,4000hz
T1CC0H = 0x0FA0 >> 8;
T1CNTL = 0; //定时器1计数器复位到0 T1CNTH = 0;

T1CC1L = 0x77; //通道1的占空比初始值
T1CC1H = 0x01; // Ticks = 375 (1,5ms initial duty cycle)
T1CC2L = 0x77;
T1CC2H = 0x01; // Ticks = 375 (1,5ms initial duty cycle)
T1CC3L = 0x77;
T1CC3H = 0x01; // Ticks = 375 (1,5ms initial duty cycle)
T1CC4L = 0x77;
T1CC4H = 0x01; // Ticks = 375 (1,5ms initial duty cycle)}

void pwm_start(void)
{
T1CTL |= 0x02;
}
void pwm_update_value(unsigned char b, unsigned char g, unsigned char r, unsigned char w)
{
r = r?r:1; // 0 PWM means max power for some reason, so set 1 for 0.
g = g?g:1;
b = b?b:1;
//赋值占空比
T1CC1L = b;
T1CC1H = 0x0;
T1CC2L = g;
T1CC2H = 0x0;
T1CC3L = r;
T1CC3H = 0x0; T1CC4L = w;
T1CC4H = 0x0;
}

接收手机数据更新占空比

case SIMPLEPROFILE_CHAR6:
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR6, Char6 );
pwm_update_value(Char6[1], Char6[2], Char6[3], Char6[4]);

wenqi lu:

回复 cedar_xuesong:

HI cedar_xuesong:

is me,扮深沉

赞(0)
未经允许不得转载:TI中文支持网 » BLE ,2540引出4路PWM,大神请进
分享到: 更多 (0)