// Wysłanie liczby na RS void usart_write_number(long number){ unsigned char i,j,k; long a,b; a=1000000000; b=999999999; // wysłanie znaku '-' if (number < 0) usart_write_byte('-'); for (i=0;i<10;i++){ j = (number / a) % 10; if ((number > b) || (i == 9)) { // zamiana na znak switch(j){ case 0: k='0'; break; case 1: k='1'; break; case 2: k='2'; break; case 3: k='3'; break; case 4: k='4'; break; case 5: k='5'; break; case 6: k='6'; break; case 7: k='7'; break; case 8: k='8'; break; case 9: k='9'; break; default: k='0'; } usart_write_byte(k); } a /= 10; b /= 10; } }
void test_timer0_with(uint64_t ps_num, uint8_t mode, uint8_t ps, uint64_t top_val) { #if defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) timer0_set_enable_OCIE0x_interrupt(OCIE0A, FALSE); #endif reset(); usart_write_string("\n\tPrescale "); usart_write_num((int)ps_num); usart_write_byte('\n'); prescale = ps_num; //top = top_val; #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) timer0_start(prescale); #elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) timer0_start(mode, ps); if(mode != TIMER0_NORMAL) { timer0_set_cycle(TIMER0_COMPARATOR_A, (uint8_t)top_val); } timer0_set_enable_OCIE0x_interrupt(OCIE0A, TRUE); while(elapsed != SINGLE_TEST_SEC); timer0_set_enable_OCIE0x_interrupt(OCIE0A, FALSE); #endif }
void setup_hardware() { uint16_t v = ADCL; usart_write_num((ADCH << 8) + v); usart_write_byte('\n'); pcd8544_cfg_t cfg; cfg.dc.ddr = &DDRB; cfg.dc.port = &PORTB; cfg.dc.pin = PB1; cfg.ss.ddr = &SPI_DDR; cfg.ss.port = &SPI_PORT; cfg.ss.pin = SPI_SS; cfg.rst.ddr = & DDRB; cfg.rst.port = & PORTB; cfg.rst.pin = PB0; adc_divide_by(ADC_DIV_128); adc_select_reference(ADC_SRC_AVCC); pcd8544_init(&cfg, 0x4, 50); pcd8544_fill(0); pcd8544_render(); current_state.current_screen = &main_screen; }
// Wysłanie łańcucha znaków z pamięci programu void usart_write_progmem_string(const char *string){ char sign; sign = pgm_read_byte(string); while (sign != '\0'){ usart_write_byte(sign); string++; sign = pgm_read_byte(string); } }
// Wysłanie łańcucha znaków na RS void usart_write_string(char *string){ while (*string != '\0'){ usart_write_byte(*string); string++; } }