TLC59731 LED 驱动芯片 C语言驱动程序

来源:互联网 发布:python chm手册 编辑:程序博客网 时间:2024/04/27 07:59

模拟通信时序
测试平台 msp430f6723 ,MCLK = 12MHz
两个TLC59731芯片,分别使用两个IO控制通信

* * bsp_tlc59731.c * *  Created on: 2017610日 *      Author: foreversun */#include "bsp_tlc59731.h"//1/12MHz *12 * 20  MCLK=12MHz//20 us 通信速度//__delay_cycles(240);//P6.3 P1.6 串行端口定义void bsp_TLC59731_init(void){    GPIO_setAsOutputPin(GPIO_PORT_P6,GPIO_PIN3);    GPIO_setOutputLowOnPin(GPIO_PORT_P6,GPIO_PIN3);    GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN6);    GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN6);}//数据移位,发送一个字节static void bsp_TLC59731_shift(uint8_t shifting ,uint8_t sel){    uint8_t bits,bang;    if(sel == SDI0_ID )        for( bits = 0; bits < 8; bits++ )      {        bang = shifting & ( 0x80 >> bits );        SDI0_HIGH();        __delay_cycles(1);        SDI0_LOW();        if ( bang > 0)         {            SDI0_HIGH();            __delay_cycles(1);            SDI0_LOW();         }        SDI_CLK();      }    if(sel == SDI1_ID){        for( bits = 0; bits < 8; bits++ )      {        bang = shifting & ( 0x80 >> bits );        SDI1_HIGH();        __delay_cycles(1);        SDI1_LOW();        if ( bang > 0)         {            SDI1_HIGH();            __delay_cycles(1);            SDI1_LOW();         }        SDI_CLK();      }    }}//数据是否结束标志发送static void bsp_TLC59731_eos( bool flag ,uint8_t sel){  uint8_t count,i;  if ( !flag )    count = 8;  else    count = 4;  for (  i = 0; i < count; i++)  {      SDI_CLK() ;  }  if(sel == SDI0_ID ){      SDI0_HIGH();      __delay_cycles(1);      SDI0_LOW();  }   if(sel == SDI1_ID){     SDI1_HIGH();     __delay_cycles(1);     SDI1_LOW();  }}//发送整个数据32bitvoid bsp_TLC59731_light(uint8_t sel ,uint8_t r, uint8_t g, uint8_t b, bool latch ){    _disable_interrupt();    bsp_TLC59731_shift(0x3A,sel);    bsp_TLC59731_shift(r,sel);    bsp_TLC59731_shift(g,sel);    bsp_TLC59731_shift(b,sel);  if (!latch)      bsp_TLC59731_eos(true,sel);  else      bsp_TLC59731_eos(false,sel);  _enable_interrupt();}
/* * bsp_tic59731.h * *  Created on: 2017年6月10日 *      Author: foreversun */#ifndef BSP_BSP_TLC59731_H_#define BSP_BSP_TLC59731_H_#include "driverlib.h"#define SDI0_ID 0x01#define SDI1_ID 0x02#define SDI_CLK() __delay_cycles(240)#define SDI0_HIGH() GPIO_setOutputHighOnPin(GPIO_PORT_P6,GPIO_PIN3)#define SDI0_LOW() GPIO_setOutputLowOnPin(GPIO_PORT_P6,GPIO_PIN3)#define SDI1_HIGH() GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN6)#define SDI1_LOW() GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN6)void bsp_TLC59731_init(void);void bsp_TLC59731_light(unsigned char sel, unsigned char r, unsigned char g, unsigned char b, bool latch );#endif /* BSP_BSP_TLC59731_H_ */
原创粉丝点击