📄 spi_tlc5615.c
字号:
#define SPI_TLC5615_C
#include "includes.h"
void spi_init(void)//SPI初始化
{
SPCR=0X50; //使能SPI,MSB先发,主模式,CPOL为0,默认4分频
}
void spi_io_init(void)
{
DDRB|=(1<<PB4)|(1<<PB5)|(1<<PB7); //PB4-SS,PB5-MOSI,PB7-SCK
PORTB|=(1<<PB4)|(1<<PB5)|(1<<PB7);//PB4拉高TLC5615不使能;MOSI,SCK为高电平
}
void spi_tlc5615(unsigned int idata)//0000 00(78 8765 4321)
{
unsigned int temp;
unsigned char temp1=0,temp2=0,status;
temp=idata<<2;//0000 7887 6543 2100
temp1=(temp&0xff00)>>8;//0000 0000 (0000 7887)
temp2=(idata&0x00ff);//0000 0000 (6543 2100)
PORTB&=~(1<<PB4);//使能TLC5615
SPDR=temp1;//传送数据高二位
do
{
status=SPSR;
}while(!(status&=0X80));
delay_nms(10);
SPSR=0;
SPDR=temp2;//传送数据低八位
do
{
status=SPSR;
}while(!(status&=0X80));
SPSR=0;
delay_nms(10);
PORTB|=(1<<PB4);//TLC5615不使能
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -