fork download
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4.  
  5. #include "lcd.h"
  6.  
  7. volatile uint32_t ovfs = 0;
  8.  
  9. ISR(TIMER1_OVF_vect) {
  10. ++ovfs;
  11. }
  12.  
  13. int main(void) {
  14. DDRB = 0xffu;
  15. TIMSK1 |= 1<<TOIE1;
  16. lcd_init(LCD_DISP_ON);
  17. sei();
  18. for (;;) {
  19. uint32_t us = 0, cm = 0;
  20. char buf[17] = {0}, tmp;
  21. uint8_t i, j, len;
  22. lcd_clrscr();
  23. DDRD |= 1<<PD0;
  24. PORTD &= ~(1<<PD0);
  25. _delay_us(2);
  26. PORTD |= 1<<PD0;
  27. _delay_us(5);
  28. PORTD &= ~(1<<PD0);
  29. DDRD &= ~(1<<PD0);
  30. while (!(PIND & (1<<PD0)));
  31. TCNT1 = 0;
  32. TCCR1B |= 1<<CS10;
  33. while (PIND & (1<<PD0));
  34. TCCR1B &= ~(1<<CS10);
  35. us = TCNT1 + (65536lu * ovfs);
  36. ovfs = 0;
  37. cm = us * 17 / 100;
  38. for (i = 0; i < 12 && (cm != 0 || i == 0 || i == 1); ++i) {
  39. buf[i] = cm % 10 + '0';
  40. cm /= 10;
  41. }
  42. len = j = i;
  43. for (--j, i = 0; i < j; ++i, --j) {
  44. tmp = buf[i];
  45. buf[i] = buf[j];
  46. buf[j] = tmp;
  47. }
  48. i = len;
  49. tmp = buf[--i];
  50. buf[i++] = '.';
  51. buf[i++] = tmp;
  52. buf[i++] = ' ';
  53. buf[i++] = 'c';
  54. buf[i++] = 'm';
  55. lcd_puts(buf);
  56. _delay_ms(1000);
  57. }
  58. return 0;
  59. }
  60.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty