我写了一个ADS7843控制4线触摸屏的程序,可是上电后只能读一次坐标,再触摸就无效了,请问是什么问题?cpu是C8051F022,代码如下:
//SPI驱动部分 void start_ads7843(void) { sck43=0; cs43=1; si43=1; sck43=1; cs43=0; }
void WriteTo7843(byte command) // 写7843命令 { byte count=0; sck43=0; for(count=0;count<8;count++) { if(command&0x80) si43=1; else si43=0; sck43=0; delay(2); sck43=1; // 上升沿有效 delay(2); command<<=1; } }
word ReadFrom7843(void) // 读7843数据 { byte count=0; word coordinate=0; for(count=0;count<12;count++) { coordinate<<=1; sck43=1; delay(2); sck43=0; // 下降沿有效 delay(2); if(so43) coordinate++; } return coordinate; }
void end_ads7843(void) { sck43=1; cs43=1; }
//触摸读屏部分 delay(200); start_ads7843(); delay(2); WriteTo7843(0x90); delay(2); sck43=1; delay(2); sck43=0; delay(2); x_coordinate=ReadFrom7843(); x_coordinate=(x_coordinate*240)/0x0fff; WriteTo7843(0xd0); delay(2); sck43=1; delay(2); sck43=0; delay(2); y_coordinate=ReadFrom7843(); y_coordinate=(y_coordinate*320)/0x0fff; end_ads7843(); lcd_cross(((byte)(x_coordinate)),((word)(y_coordinate)),0); |