Hier mal meine Vorstellung:
Der Link der Datenblattes lautethttp://www.robotikhardware.de/download/srf02doku.pdfCode:#include <stdlib.h> #include <avr/io.h> #include "i2cmaster.h" #include "asuro.h" #define SRF02 0xE0 // device address int main(void) { unsigned char ret; int i; int t1, t2; Init(); // init Asuro i2c_init(); // init I2C interface while(1) { ret = i2c_start(SRF02+I2C_WRITE); // set device address and write mode if ( ret ) { /* failed to issue start condition, possibly no device found */ i2c_stop(); StatusLED(RED); for (i=0; i<255; i++) {Sleep(255);} } else { i2c_write(0x51); // Startbefehl zum Start der Messsung i2c_stop(); // for (i=0;i<65;i++){Sleep(72);} // mind. 65 ms warten bis Lesebefehl } i2c_write(0x02); i2c_rep_start(SRF02+I2C_READ); t1 = i2c_read(); i2c_stop(); i2c_write(0x03); i2c_rep_start(SRF02+I2C_READ); t2 = i2c_read(); i2c_stop(); char text[6] =" "; itoa(t1, text, 6); SerWrite(text, 6); SerWrite(" ", 6); char text2[6] =" "; itoa(t2, text2, 6); SerWrite(text2, 6); SerWrite("\r\n", 2); /* Zeilenvorschub */ for (i=0; i<255; i++) {Sleep(255);} } return 0; }
Danke für die Unterstützung.







Zitieren

Lesezeichen