static void dbg_mem(uint8_t *mm, const int max, struct debug_t *debug) { int i=0; uint8_t j; while (i<max) { strcpy_P (debug->line, PSTR("Byte [")); debug->string = utoa(i, debug->string, 16); strcat (debug->line, debug->string); strcpy_P (debug->string, PSTR(" - ")); strcat (debug->line, debug->string); debug->string = utoa(i + PRINT_VALUE_X_LINE - 1, debug->string, 16); strcat (debug->line, debug->string); strcpy_P (debug->string, PSTR("]: ")); strcat (debug->line, debug->string); for (j=0; j < PRINT_VALUE_X_LINE; j++) if ((i+j) < max) { debug->string = utoa(*(mm+i+j), debug->string, 16); strcat (debug->line, debug->string); strcpy_P (debug->string, PSTR(" ")); strcat (debug->line, debug->string); } uart_printstr (debug->line); uart_putchar ('\n'); i += j; } uart_putchar ('\n'); }
void debug_print_P(PGM_P string, struct debug_t *debug) { if (debug->active) { strcpy_P(debug->line, string); uart_printstr(debug->line); } }
void getDate(int *yy, int *mm, int *dd) { unsigned char c; char str[25]; int i; // Get date from user // modify values yy, mm, dd uart_printstr("Please Enter Year (yyyy):"); for (i=0;i<=4-1;i++){ c = uart_getc(); // Get character uart_putc(c); // Echo it back str[i] = c; } str[i] = '\0'; }
/******************************* Main Program Code *************************/ int main(void) { // configure the microprocessor pins for the data lines lcd_D7_ddr |= (1<<lcd_D7_bit); // 4 data lines - output lcd_D6_ddr |= (1<<lcd_D6_bit); lcd_D5_ddr |= (1<<lcd_D5_bit); lcd_D4_ddr |= (1<<lcd_D4_bit); // configure the microprocessor pins for the control lines lcd_E_ddr |= (1<<lcd_E_bit); // E line - output lcd_RS_ddr |= (1<<lcd_RS_bit); // RS line - output // configure the microprocessor pins for the pushbutton pushbutton_ddr &= (1<<pushbutton_bit); pushbutton_port |= (1<<pushbutton_bit); // initialize adc ADMUX = ((1<<REFS0)|(1<<MUX2)|(1<<MUX0)); // Aref = Vcc, select ADC5 ADCSRA = ((1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<ADPS0)); // Prescaler div factor = 128 // initialize the LCD controller as determined by the defines (LCD instructions) lcd_init_4d(); // initialize the LCD display for a 4-bit interface // initialize TWI i2c_init(); // initialize thermometer therm_init(); // display the first line of information lcd_write_string_4d(disp_time); // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) // Code for interfacing with the serial connection char str[25]; int yy,mm,dd; sei(); // Enable global interrupts uart_init(); // Initialize the USART using baud rate 9600 uart_printstr(sdata); // Print a string from SRAM uart_printstr(fdata); // Print a string from FLASH getDate(&yy,&mm,&dd); // Get date from user sprintf(str,"Date: %d/%d/%d\n",yy,mm,dd); uart_printstr(str); // endless loop while(1) { uart_printstr(sdata); // Print a string from SRAM uart_printstr(fdata); // replace with check for button press function if(bit_is_clear(pushbutton_pin,pushbutton_bit)) { _delay_ms(100); if(bit_is_clear(pushbutton_pin,pushbutton_bit)) mode_new = (mode + 1) % 3; } if(mode_new != mode) { // clear lcd lcd_write_instruction_4d(lcd_clear); // display the first line of information // set cursor to start of first line lcd_write_instruction_4d(lcd_setCursor | lcd_lineOne); _delay_us(40); // 40 uS delay (min lcd_write_string_4d(disp_time); // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) if (mode_new == 0) { voltage = read_ADC(); lcd_write_string_4d(disp_volt); } else if (mode_new == 1) { frequency = 10 * freq_cntr_get_frequency(); lcd_write_string_4d(disp_freq); } else { temp_calcTemp(); // test thermometer lcd_write_string_4d(disp_temp); } } mode = mode_new; } return 0; }
void debug_print(struct debug_t *debug) { if (debug->active) uart_printstr(debug->line); }