#include <LiquidCrystal.h>
LiquidCrystal myLCD(13, 12, 11, 10, 9, 8);
#define key 21
#define led 20
int loopCounter, intCounter;
bool ledState = LOW;
void setup() {
myLCD.begin(16, 2);
pinMode(key, INPUT_PULLUP);
pinMode(led, OUTPUT);
noInterrupts();
TCCR1A = 0; // Скидання регістру TCCR1A
TCCR1B = 0; // Скидання регістру TCCR1B
bitSet(TCCR1B, CS11);
bitSet(TCCR1B, CS10); //Джерело тактування: CLK/64
bitSet(TIMSK1, TOIE1); // Дозвіл переривання при переповненні таймера-лічильника 1
interrupts();
}
void display() {
myLCD.setCursor(0,0);
myLCD.print("loopCounter=");
myLCD.print(loopCounter);
myLCD.setCursor(0,1);
myLCD.print(" intCounter=");
myLCD.print(intCounter);
delay(200);
}
ISR(TIMER1_OVF_vect){
intCounter++;
ledState = !ledState;
digitalWrite(led, ledState);
}
void loop() {
loopCounter++;
display();
if (digitalRead(key) == LOW) delay(5000);
}