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

模拟通信时序
测试平台 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();
  }
}
//发送整个数据32bit
void 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_ */
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值