SPIspi(p5,p6,p7);// mosi(out), miso(in), sclk(clock)DigitalOutcs(p8);// cs (the chip select signal)Serialpc(USBTX,USBRX);intmain(){spi.format(8,1);//(bits, mode) (mode1 (CPOL=0, CPHA=1)spi.frequency(1000000);//1MHzwait_ms(20);//Delay for minimum of 16ms to allow power supplies to settle and power-on reset to complete.cs=0;// Select the device by seting chip select lowwait_ms(1);//Delay for minimum of tsccs(=10ns)spi.write(0x06);//resetwait_ms(1);//Delay for minimum of 0.6msspi.write(0x16);//SDATAC: Stop read data continuous mode.wait_ms(1);//WREG: Write to register rrrrspi.write(0x40);//WREG, MUX0spi.write(0x00);//spi.write(0x01);//AIN0 = + , AIN1 = -wait_ms(1);spi.write(0x42);//System Control Register0spi.write(0x00);//spi.write(0x30);//Internal Reference is always on. & Internal Reference selected.wait_ms(1);spi.write(0x43);//System Control Register0spi.write(0x00);//spi.write(0x12);//PGA=2, Data Output Rate = 20SPSwait_ms(1);spi.write(0x04);//SYNC: Synchronize ADC conversions.wait_ms(1);cs=1;while(1){cs=0;spi.write(0x12);//RDATA: Read data once.wait_ms(1);unsignedcharVolt_hex1=spi.write(0xff);unsignedcharVolt_hex2=spi.write(0xff);unsignedshortVolt_hex=(Volt_hex1<<8)|Volt_hex2;floatVolt=(float)Volt_hex/0x7fff;//0 ~ 1.024Vcs=1;pc.printf("%f\r",Volt);wait(1);}}