ld3320用软件模拟spi,是不是通讯不成功呢?应该怎么搞呢,没头绪,用的是51单片机。
2019-07-15 08:11发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
//请问是什么原因?请各路大神提供指点,小弟将感激不尽!
//我只改了io口;sbit SCS=P2^3; //芯片片选信号CSsbit SDCK=P2^4; //SPI 时钟信号P2sbit SDI=P2^5; //SPI 数据输入P0sbit SDO=P2^6; //SPI 数据输出P1sbit SPIS=P2^1; //SPI 模式设置:低有效。 wrsbit RSTB=P2^2; //RST
//这是我的读写程序,这也是芯片资料提供的没有改过;void LD_WriteReg(unsigned char address, unsigned char dataout) { unsigned char i = 0; unsigned char command=0x04; SPIS =0; SCS = 0; DELAY_NOP;
//write command for (i=0;i < 8; i++) { if ((command & 0x80) == 0x80) SDI = 1; else SDI = 0;
DELAY_NOP; SDCK = 0; command = (command << 1); DELAY_NOP; SDCK = 1; } //write address for (i=0;i < 8; i++) { if ((address & 0x80) == 0x80) SDI = 1; else SDI = 0; DELAY_NOP; SDCK = 0; address = (address << 1); DELAY_NOP; SDCK = 1; } //write data for (i=0;i < 8; i++) { if ((dataout & 0x80) == 0x80) SDI = 1; else SDI = 0; DELAY_NOP; SDCK = 0; dataout = (dataout << 1); DELAY_NOP; SDCK = 1; } DELAY_NOP; SCS = 1; }
unsigned char LD_ReadReg(unsigned char address) { unsigned char i = 0; unsigned char datain =0; unsigned char temp = 0; unsigned char command=0x05; SPIS =0; SCS = 0; DELAY_NOP;
//write command for (i=0;i < 8; i++) { if ((command & 0x80) == 0x80) SDI = 1; else SDI = 0; DELAY_NOP; SDCK = 0; command = (command << 1); DELAY_NOP; SDCK = 1; }
//write address for (i=0;i < 8; i++) { if ((address & 0x80) == 0x80) SDI = 1; else SDI = 0; DELAY_NOP; SDCK = 0; address = (address << 1); DELAY_NOP; SDCK = 1; } DELAY_NOP;
//Read data for (i=0;i < 8; i++) { datain = (datain << 1); temp = SDO; DELAY_NOP; SDCK = 0; if (temp == 1) datain |= 0x01; DELAY_NOP; SDCK = 1; }
DELAY_NOP; SCS = 1; return datain; }
-
-
语音模块程序.docx
下载积分: 积分 -1 分
17.81 KB, 下载次数: 0, 下载积分: 积分 -1 分
一周热门 更多>