本人写了一个关于12位A/D转换芯片,TLC2543与ARM7芯片的接口程序,写入芯片的子函数已经调试通过,还有读取的函数一时无法调试完成,还望高手指点!谢谢! void SPI_Write(unsigned char _data){ uint8 i; IO0SET =IO0PIN|SPI_CS; DelayNS(2); IO0CLR=IO0PIN|SPI_CS; for (i=0;i<=7;i++){ if(_data&0x80){ IO0CLR=IO0PIN|SCK; IO0SET=IO0PIN|SDO; DelayNS(2); IO0SET=IO0PIN|SCK; DelayNS(2); } else{ IO0CLR=IO0PIN|SCK; IO0CLR=IO0PIN|SDO; DelayNS(2); IO0SET=IO0PIN|SCK; DelayNS(2); } _data<<=1; } IO0SET=IO0PIN|SPI_CS; }
uint8 SPI_Read(void){ uint8 uwd_voltage = 0; uint8 i; IO0SET =IO0PIN|SPI_CS; DelayNS(1); IO0CLR=IO0PIN|SPI_CS; DelayNS(1); for (i=0;i<=7;i++){ IO0SET=IO0PIN|SCK; DelayNS(1); if (IO0PIN&SDI){ uwd_voltage|=0x80; //uwd_voltage &=0x80; } else{ uwd_voltage>>=1; } IO0CLR=IO0PIN|SCK; DelayNS(1); }
IO0SET=IO0PIN|SPI_CS; DelayNS(2);
return uwd_voltage; }
|