prjbrook

ArduinoTimer2

Jul 23rd, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  4. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  5.  
  6. const int lcdContrastPin = 6, lcdBackligthPin = 10;
  7.  
  8. void setup()
  9. {
  10. // tutn on LCD backlight and contrast
  11. pinMode(lcdContrastPin, OUTPUT);
  12. pinMode(lcdBackligthPin, OUTPUT);
  13.  
  14. // fine-tuning contrast could be done by PWM on lcdContrastPin
  15. digitalWrite(lcdContrastPin, LOW);
  16. digitalWrite(lcdBackligthPin, HIGH);
  17.  
  18. lcd.begin(16, 2);
  19.  
  20. // configure Timer1
  21. TCCR1A = 0; // no waveform generation
  22. TCCR1B = 0x00000010; // frequency divider 8 (i.e. counting with 2 MHz)
  23. TCCR1C = 0;
  24. TIFR1 = 0x00100000; // clear Input Capture Flag
  25. TCNT1 = 333;
  26. }
  27.  
  28. void loop()
  29. {
  30. int currentTimerValue = TCNT1;
  31.  
  32. lcd.setCursor(0, 0);
  33. lcd.print("TCNT1=");
  34. lcd.print(currentTimerValue);
  35. lcd.println(" ");
  36.  
  37. delay(50);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment