// *********************************************************** // Project: Loadcell to RS232 Interface via HX711, // Micrometer dial to RS232 via hex interface // Author: Dr. Simon Schroedle // Module description: Standalone to run on ATMEGA8-16PU; // data are transmitted as HEX values // W: load cell data // D: dial data // *********************************************************** // configuration #define F_CPU 7372800 #define HX711_CLOCK_PIN C,0 #define HX711_DATA_PIN C,1 #define DIAL_CLOCK_PIN D,2 //INT0 input #define DIAL_DATA_PIN C,2 #include #include #include #define BAUD 115200UL #define UBRR_BAUD ((F_CPU/(16UL*BAUD))-1) #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) // clever runden #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) // Reale Baudrate #define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) // Fehler in Promille, 1000 = kein Fehler. #if ((BAUD_ERROR<990) || (BAUD_ERROR>1010)) #error Systematischer Fehler der Baudrate grösser 1% und damit zu hoch! #endif /// Set the specified pin high. #define AVRPIN_SET(x) __AVRPIN_SET(x) #define __AVRPIN_SET(p,b) PORT##p |= 1<>8); UBRRL = (uint8_t) (UBRR_BAUD & 0x0ff); UCSRB = (1<>20)&0x0fL]); usend (ihex[(value>>16)&0x0fL]); usend (ihex[(value>>12)&0x0fL]); usend (ihex[(value>>8)&0x0fL]); usend (ihex[(value>>4)&0x0fL]); usend (ihex[value&0x0fL]); usend ('T'); usend (ihex[(hx711_last_timeh>>4)&0x0f]); usend (ihex[hx711_last_timeh&0x0f]); usend (ihex[(hx711_last_timel>>4)&0x0f]); usend (ihex[hx711_last_timel&0x0f]); } if( dial_read_32( &value ) ) { usend ('D'); usend (ihex[(value>>8)&0x0fL]); usend (ihex[(value>>4)&0x0fL]); usend (ihex[value&0x0fL]); usend (ihex[(value>>20)&0x0fL]); //stats and sign usend ('T'); usend (ihex[(dial_last_timeh>>4)&0x0f]); usend (ihex[dial_last_timeh&0x0f]); usend (ihex[(dial_last_timel>>4)&0x0f]); usend (ihex[dial_last_timel&0x0f]); } } }