varli_ketanpl

SMI_LAB6_EX1

Nov 6th, 2023
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <util/delay.h>
  2. #include <LiquidCrystal.h>
  3. LiquidCrystal lcd(12, NULL, 11, 9, 8, 7, 6);
  4. volatile int nr_secunde = 50;
  5. volatile int minutes = 59;
  6. volatile int hours = 0;
  7.  
  8. void setup() {
  9.   TIMSK1 = (1 << TOIE1);  // activare timer overflow
  10.   TCCR1A = 0;
  11.   TCCR1B = 0;  // timer stop
  12.   //activare INT0, INT1, PCINT20
  13.   EIMSK = (1 << INT0);
  14.   EIMSK |= (1 << INT1);
  15.   //activare PCI2 (buton 3 - PCINT20 - PCI2)
  16.   PCICR |= (1 << PCIE2);
  17.   PCMSK2 |= (1 << PCINT20);
  18.   //configurare LCD
  19.   lcd.begin(16, 2);
  20.   lcd.noCursor();
  21. }
  22.  
  23. void loop() {
  24.   lcd.setCursor(0, 1);
  25.  
  26.   if (hours < 10) lcd.print("0");
  27.   lcd.print(hours);
  28.   lcd.print("h");
  29.  
  30.   if (minutes < 10) lcd.print("0");
  31.   lcd.print(minutes);
  32.   lcd.print("m");
  33.  
  34.   if (nr_secunde < 10) lcd.print("0");
  35.   lcd.print(nr_secunde);
  36.   lcd.print("s");
  37. }
  38.  
  39. ISR(TIMER1_OVF_vect) {
  40.   TCNT1 = 0x0BDC;
  41.   nr_secunde++;
  42.   if (nr_secunde == 60) {
  43.     nr_secunde = 0;
  44.     minutes++;
  45.   }
  46.  
  47.   if (minutes == 60) {
  48.     minutes = 0;
  49.     hours++;
  50.   }
  51. }
  52.  
  53. ISR(INT0_vect) {
  54.   TCNT1 = 0x0BDC;
  55.   TCCR1A = 0;
  56.   TCCR1B = (1 << CS12);  // timer start
  57.   _delay_ms(400);
  58. }
  59. ISR(INT1_vect) {
  60.   TCCR1A = 0;
  61.   TCCR1B = 0;  // timer stop
  62.   _delay_ms(400);
  63. }
  64.  
  65. ISR(PCINT2_vect) {
  66.   nr_secunde = 0;  //reset cronometru
  67.   minutes = 0;
  68.   hours = 0;
  69.   _delay_ms(400);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment