UCB1CTL0 |= UCMST+UCMSB+UCSYNC+UCCKPL; // 3-pin, 8-bit SPI master,Clock polarity high, MSB
UCB1CTL1 |= UCSSEL_1; // CLOCK ACLK UCB1BR0 = 0x06; UCB1BR1 = 0;
UCB1CTL1 &= ~UCSWRST; //置位UCSWRST,开始传输数据 /*****************TEST*********TEST***************TEST*********/
//read all REG value using default setting //char orgVal[20]; //write to register
spi_writeByte(RPMAX,RpMAX); //RP_MAX=21.547kohm spi_writeByte(RPMIN,RpMIN); //RP_MIN=3.078kohm spi_writeByte(SENSORFREQ, 0xB3); //register value:148 0x94
spi_writeByte(LDCCONFIG, 0x17); //设置振荡器振幅:4V,响应时间:6144
spi_writeByte(CLKCONFIG, 0x00); //设置LDC时钟为外部时基
spi_writeByte(INTCONFIG, 0x02); //010: INTB pin indicates the status of Comparator output
16
spi_writeByte(THRESHILSB, 0x50);
spi_writeByte(THRESHIMSB, 0x14); //Comparator Threshold High 5200
spi_writeByte(THRESLOLSB, 0xC0);
spi_writeByte(THRESLOMSB, 0x12); Threshold Low 4800
spi_writeByte(PWRCONFIG, 0x01); Conversion is Enabled //read all registers
//spi_readBytes(REVID, &orgVal[0],18); int i;
spi_readBytes(PROXLSB,&p[0],2); spi_readBytes(FREQCTRLSB,&freq[0],3); pMAX = ((unsigned char) p[1]<<8) + p [0]; freqMAX = ((unsigned char)freq[1]<<8) + freq[0]; pMIN = pMAX; freqMIN = freqMAX; for (i=0;i<100;i++) {
spi_readBytes(PROXLSB,&p[0],2); spi_readBytes(FREQCTRLSB,&freq[0],3); pTEMP = ((unsigned char)p[1]<<8) + p [0];
//Comparator //Active Mode. 17
freqTEMP = ((unsigned char)freq[1]<<8) + freq[0]; if (pTEMP < pMIN) pMIN = pTEMP; if (freqTEMP < freqMIN) freqMIN = freqTEMP; if (pTEMP > pMAX) pMAX = pTEMP; if (freqTEMP > freqMAX) freqMAX = freqTEMP; //spi_readbytes(LDC1000_CMD_STATUS,) //read all registers using extended SPI }
init=(pMAX+pMIN)/2; Low=init-50; High=init+50; set_direction('X',0); X=6000; delay_ms(200); X=0; delay_s(1); //while (1) //{
18
wr_int(3,0,pMIN); wr_int(3,1,pMAX); wr_int(4,2,freqMIN); wr_int(4,3,freqMAX); init_location(); set_direction('Y',1); Y=8000; delay_ms(1000); Y=0; for(;;) {
if(get==1) break; else {
set_direction('X',0); scan(); } if(get==1) break; else {
19
set_direction('X',1); scan(); } if(get==1) break; else {
Y=8000; delay_ms(200); } }
wr_int(6,0,1); wr_int(3,0,pMIN); wr_int(3,1,pMAX); wr_int(4,2,freqMIN); wr_int(4,3,freqMAX); __no_operation(); //} }
20