STM32 TLC6983底层驱动代码
时间: 2023-12-20 18:56:24 浏览: 62
TLC5615 STM32驱动程序
5星 · 资源好评率100%
TLC6983是一款常用的LED驱动芯片,常用于LED显示屏幕的控制。下面给出一个基于STM32的TLC6983底层驱动代码示例:
```
#include "stm32f10x.h"
#define TLC6983_PORT GPIOB
#define TLC6983_LE_PIN GPIO_Pin_12
#define TLC6983_CLK_PIN GPIO_Pin_13
#define TLC6983_SIN_PIN GPIO_Pin_14
void TLC6983_Init() {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = TLC6983_LE_PIN | TLC6983_CLK_PIN | TLC6983_SIN_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(TLC6983_PORT, &GPIO_InitStructure);
TLC6983_PORT->BSRR = TLC6983_LE_PIN;
}
void TLC6983_Write(uint16_t data) {
TLC6983_PORT->BRR = TLC6983_LE_PIN;
for (uint8_t i = 0; i < 16; i++) {
if (data & 0x8000) {
TLC6983_PORT->BSRR = TLC6983_SIN_PIN;
} else {
TLC6983_PORT->BRR = TLC6983_SIN_PIN;
}
data <<= 1;
TLC6983_PORT->BRR = TLC6983_CLK_PIN;
TLC6983_PORT->BSRR = TLC6983_CLK_PIN;
}
TLC6983_PORT->BSRR = TLC6983_LE_PIN;
}
```
这个代码示例假设TLC6983的LE、CLK、SIN引脚分别连接到了STM32的GPIOB12、GPIOB13、GPIOB14上。在初始化函数中,我们首先开启GPIOB时钟,并设置这些引脚为输出模式。在写入数据函数中,我们首先将LE引脚拉低,然后逐位写入数据,最后再将LE引脚拉高。
阅读全文