📄 max531.h
字号:
void SPI_Init(void)
{
DDR_SPI |= (1<<MOSI)|(1<<SCK); //|(1<<SS);1 as output
DDR_SPI &=~(1<<MISO);// 0 as input
PORTB |= (1<<MOSI)|(1<<SCK); //|(1<<SS);
SPCR |= (1<<SPR1)|(1<<SPR0); //主机模式时的时钟分频选择00——1/4分频,01——1/16分频,10——1/64分频,11——1/128分频
SPCR |= (1<<MSTR); //决定SPI的主从关系,1——主机模式,0——从机模式
SPCR |= (1<<SPE); //使能SPI,进行任何SPI操作前都必须先使能该位
}
void max531(unsigned int senddata)
{
unsigned char temphi,templo;
cSREG=SREG;
CLI();
DDRB |= (1<<CS_531);
PORTB &=~BIT(CS_531); //片选
temphi = (senddata>>8)&0xff; //发送字节高8位(12bit);
templo = senddata&0xff; //发送字节低8位(12bit);
SPDR = temphi;
while(!(SPSR&(1<<SPIF))); //等待转换完成
SPDR = templo;
while(!(SPSR&(1<<SPIF))); //等待转换完成
PORTB|=BIT(CS_531); //取消片选
SREG=cSREG;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -