?? 新建 文本文檔 (3).txt
字號:
#define SET_MAX525_CS PORTB|=0x10
#define CLR_MAX525_CS PORTB&=~0x10
void spi_init(void)
{
//spi初始化
DDRB=0xbf;
PORTB=0x0F;
SPCR = 0x53;
SPSR = 0x00;
}
//使用SPI發(fā)送一個字節(jié)
void spi_write(uchar sData)
{
SPDR = sData;
while(!(SPSR & BIT(SPIF)));
//sData=SPDR;//讀從機發(fā)回來的數(shù)據(jù)
}
void max525_write(unsigned int A,unsigned int B,unsigned int C,unsigned int D)
{
unsigned char i,tempAH,tempAL,tempBH,tempBL,tempCH,tempCL,tempDH,tempDL;
unsigned int mytemp1,mytemp2;
CLI();
mytemp1=A&0x0fff;
mytemp2=A;
tempAH=(mytemp1&0xff00)>>8;
tempAL=(mytemp2&0x00ff);
mytemp1=B&0x0fff;
mytemp2=B;
tempBH=(mytemp1&0xff00)>>8;
tempBL=(mytemp2&0x00ff);
mytemp1=A&0x0fff;
mytemp2=A;
tempCH=(mytemp1&0xff00)>>8;
tempCL=(mytemp2&0x00ff);
mytemp1=D&0x0fff;
mytemp2=D;
tempDH=(mytemp1&0xff00)>>8;
tempDL=(mytemp2&0x00ff);
CLR_MAX525_CS;
delay_nus(20);
spi_write(tempAH+0x30);
spi_write(tempAL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);
spi_write(tempBH+0x70);
spi_write(tempBL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);
spi_write(tempCH+0xB0);
spi_write(tempCL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);
spi_write(tempDH+0xF0);
spi_write(tempDL);
SET_MAX525_CS;
delay_nus(20);
SEI();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -