//----------------------------------------------------------------------------- #include "application.h" #include "usart.h" #include //----------------------------------------------------------------------------- volatile U08 app_reset_source; //----------------------------------------------------------------------------- void app_init(void) { app_reset_source = MCUSR; // Save last reset source MCUSR = 0x00; // Clear reset source for next reset cycle // Dangerous here: I still do not know much about the watchdog. // This code is still from Udo Juerss. // The watchdog timer is disabled by default ("startup.asm") #ifdef USE_WATCHDOG WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms) #endif // define PORTS // USART DDRD &= ~(1< output DDRC |= 0x7F; // SB-pins -> output // SPI // set all CS's: output DDRB |= (1 << SPI_E_CS); DDRD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS); // set all Chips selects HIGH PORTB |= (1 << SPI_E_CS); PORTD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS); // set MOSI and SCK: output & // set MISO: input SPI_DDR |= (1 << SPI_MOSI); SPI_DDR |= (1 << SPI_SCLK); SPI_DDR &= ~(1 << SPI_MISO); // set MOSI, SCK: HIGH. MISO leave alone. SPI_PRT |= (1 << SPI_MOSI); SPI_PRT |= (1 << SPI_SCLK); //SPI_PRT |= (1 << SPI_MISO); // ADC DDRD &= ~(1<=5) && (usart_rx_buffer[2] >= 'A' && usart_rx_buffer[2] <= 'H')) { usart_write_char(usart_rx_buffer[2]); usart_write_str((pU08)" to "); usart_write_U08_hex(usart_rx_buffer[4]); usart_write_char('\n'); ad7719_enables[usart_rx_buffer[2]-'A']=usart_rx_buffer[4]; ad7719_channels_ready[usart_rx_buffer[2]-'A']=0x00; } else if ((usart_received_chars=3) && (usart_rx_buffer[1] >= 'A' && usart_rx_buffer[1] <= 'H')) { usart_write_char(usart_rx_buffer[1]); if (usart_rx_buffer[2]!='0') { usart_write_str((pU08)" to 0xFF\n"); ad7719_enables[usart_rx_buffer[1]-'A']=0xFF; } else { usart_write_str((pU08)" to 0x00\n"); ad7719_enables[usart_rx_buffer[1]-'A']=0x00; } ad7719_channels_ready[usart_rx_buffer[1]-'A']=0x00; } else { usart_write_str((pU08)"\n something wrong\n"); usart_write_str((pU08)"usart_rx_buffer_index: "); usart_write_U08(usart_received_chars, 3); usart_write_str((pU08)"\n usart_rx_buffer[2]: "); usart_write_char(usart_rx_buffer[2]); usart_write_str((pU08)"\n usart_rx_buffer[4]: "); usart_write_U08_hex(usart_rx_buffer[4]); usart_write_char('\n'); } } void set_adc_enable_register() { // TODO usart_write_str((pU08)"setting of ATmega internal ADC enable registers is not supported. yet.\n"); } U08 increase_adc (U08 channel){ U08 effective_channel; for ( U08 increase = 1 ; increase <= V_CHANNELS + I_CHANNELS + H_CHANNELS; increase++) { effective_channel = (channel + increase) % (V_CHANNELS + I_CHANNELS + H_CHANNELS); if (adc_enables[effective_channel/8] & (1<