//----------------------------------------------------------------------------- #include "typedefs.h" #include "application.h" #include "spare_outs.h" #include "spi_master.h" #include "ad7719_adc.h" #include "usart.h" #include "macros.h" #include "interpol.h" #include "w5100_spi_interface.h" #include #include #include #include "tests.h" //----------------------------------------------------------------------------- int main(void) { // U08 IDN_STR[] = "16ch Pt1000 logger; firmware version of 07.11.10. DN"; // Identity string spare_outs_init(); //set spare out pin I/O modes app_init(); // Setup software modules usart_init(); // Initialize serial interface spi_init(); // Initialize SPI interface as master adc_init(); // Initialize AD7719 ADC as SPI slave // usart_write_crlf(); // usart_writeln_flash_str(IDN_STR); // Write string to USART interface // usart_write_crlf(); // Enable interrupts sei(); // temperature muxer pins init: // SA - pins DDRA |= 0x3F; // set all SA-pins as outputs // voltage, current, humidity - muxer pins: // SB - pins DDRC |= 0x7F; // set all SB - pins as outputs // SB - muxer test // DDRA |= 1< heartbeat adc_init(); ++Res_or_Volt; if (Res_or_Volt <= 64){ // if USART data arrives. i.e. data via USB // the usart_rx_ready flag is set TRUE // now process the incoming data which is stored in // U08 usart_rx_buffer[USART_RX_BUFFER_SIZE] // and tell the USART interface, it may receive new data // by setting the usart_rx_ready flag FALSE again ++SA_mux_val; if (Res_or_Volt == 1) SB_mux_val = 16; else if (SA_mux_val == 64) SA_mux_val = 32; else if (SA_mux_val == 16) SA_mux_val = 48; else if (SA_mux_val == 32) SA_mux_val = 0; PORTA = (SA_mux_val & 0x3F); // usart_write_str((pU08)"SA:"); usart_write_U08(SA_mux_val,2); usart_write_str((pU08)" Sensor:"); usart_write_U08((SA_mux_val % 8)+1,2); usart_write_str((pU08)" an Temperatur_"); switch (SA_mux_val / 8) { case 0: usart_write_str((pU08)"C"); break; case 1: usart_write_str((pU08)"D"); break; case 2: usart_write_str((pU08)"A"); break; case 3: usart_write_str((pU08)"B"); break; case 4: usart_write_str((pU08)"G"); break; case 5: usart_write_str((pU08)"H"); break; case 6: usart_write_str((pU08)"E"); break; case 7: usart_write_str((pU08)"F"); break; default: usart_write_str((pU08)"alarm!"); break; } // usart_write_str((pU08)"\n"); usart_write_str((pU08)" "); startconv(); while (!ADC_IS_READY()) { // just wait until ADC is redy -- really bad code here! } resistance = getresistance(); //Start a new A/D Conversion //temp = readandsendtemp(); //adcword = getadc(); //temperature = gettemp(); usart_write_str((pU08)"R:"); usart_write_float(resistance,3,4); usart_write_str((pU08)"kOhm "); //_delay_ms(200); startconv(); while (!ADC_IS_READY()) { // just wait until ADC is redy -- really bad code here! } //Start a new A/D Conversion //temp = readandsendtemp(); //adcword = getadc(); resistance = getresistance(); //temperature = gettemp(); usart_write_str((pU08)"R:"); usart_write_float(resistance,3,4); usart_write_str((pU08)"kOhm "); //usart_write_str((pU08)"\n"); switch (SA_mux_val) { case 7: usart_write_str((pU08)"\n\n"); break; case 15: usart_write_str((pU08)"\n\n"); break; case 23: usart_write_str((pU08)"\n\n"); break; case 31: usart_write_str((pU08)"\n\n"); break; case 39: usart_write_str((pU08)"\n\n"); break; case 47: usart_write_str((pU08)"\n\n"); break; case 55: usart_write_str((pU08)"\n\n"); break; case 63: usart_write_str((pU08)"\n\n"); break; default: usart_write_str((pU08)"\n"); break; } SB_mux_val = 0; } else if (Res_or_Volt == 148) Res_or_Volt = 0; else { ++SB_mux_val; if (SB_mux_val == 84) SB_mux_val = 0; else if (SB_mux_val == 74) SB_mux_val = 82; else if (SB_mux_val == 82) SB_mux_val = 72; else if (SB_mux_val == 72) SB_mux_val = 74; else if (SB_mux_val == 48) SB_mux_val = 64; else if (SB_mux_val == 64) SB_mux_val = 32; else if (SB_mux_val == 32) SB_mux_val = 48; PORTC = (SB_mux_val & 0x7F); usart_write_str((pU08)"8bit-ADC: "); if (SB_mux_val < 64) { switch (SB_mux_val / 16) { case 0: usart_write_str((pU08)"voltage_A: "); break; case 1: usart_write_str((pU08)"voltage_B: "); break; case 2: usart_write_str((pU08)"voltage_D: "); break; case 3: usart_write_str((pU08)"voltage_C: "); break; } if (SB_mux_val % 2 == 0) { usart_write_str((pU08)"U"); usart_write_U08( (SB_mux_val%16)/2 , 1 ); } else { usart_write_str((pU08)"I"); usart_write_U08( ((SB_mux_val%16)-1)/2 , 1 ); } } else { if (SB_mux_val < 72) { usart_write_str((pU08)"voltage_E: "); if (SB_mux_val % 2 == 0) { usart_write_str((pU08)"U"); usart_write_U08( (SB_mux_val%8)/2 , 1 ); } else { usart_write_str((pU08)"I"); usart_write_U08( ((SB_mux_val%8)-1)/2 , 1 ); } } else if (SB_mux_val == 72) usart_write_str((pU08)"humidity_A: H0"); else if (SB_mux_val == 73) usart_write_str((pU08)"humidity_A: H1"); else if (SB_mux_val < 82) { usart_write_str((pU08)"voltage_F: "); if (SB_mux_val % 2 == 0) { usart_write_str((pU08)"U"); usart_write_U08( ((SB_mux_val-2)%8)/2 , 1 ); } else { usart_write_str((pU08)"I"); usart_write_U08( (((SB_mux_val-2)%8)-1)/2 , 1 ); } } else if (SB_mux_val == 82) usart_write_str((pU08)"humidity_B: H0"); else if (SB_mux_val == 83) usart_write_str((pU08)"humidity_B: H1"); } for (U08 counter = 0; counter < 1; ++counter) { ADCSRA |= (1<