智能车制作
标题:
mma7455怎么用spi编程
[打印本页]
作者:
hyz229426897
时间:
2013-8-12 22:32
标题:
mma7455怎么用spi编程
void SPI0_Init() {
SPI0BR=0x55; //波特率2048
SPI0CR1=0x5e; //模块使能,主机模块
SPI0CR2=0x10;
}
void SPI0_Send_Data(){
cs=0;
SPI0DR=0x08;
while(!(SPI0SR_SPTEF)); //等待SPTEF 为0
cs=1;
}
SPI0_Receive_Data(){
cs=0;
LCD_set_XY(1,1);
LCD_write_char_my(font6x8[16]);
while(!(SPI0SR_SPIF));
return SPI0DR;
cs=1;
}
void main() {
Pll_Init();
DDRA=0xff;
DDRP=0xff;
LCD_init();
LCD_clear();
DDRM=0x2f;
MODRR_MODRR4=1;
SPI0_Init();
EnableInterrupts;
for(;;){
//cs=0;
//PTM_PTM3=0;
SPI0_Send_Data();
a=SPI0_Receive_Data();
LCD_set_XY(0,0);
LCD_write_char_my(font6x8[a/100+16]);
LCD_set_XY(6,0);
LCD_write_char_my(font6x8[a/10%10+16]);
LCD_set_XY(12,0);
LCD_write_char_my(font6x8[a%10+16]);
delayms(3000);
//cs=1;
//PTM_PTM3=1;
}
}
用示波器读sdi波型是0x08 为什么出来的数据总是0 求大神啊·······
作者:
冷落义墨
时间:
2013-11-8 12:40
我用51模拟iic模式 读出来的也都是0 无语了
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2