Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <util/delay.h>
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, NULL, 11, 9, 8, 7, 6);
- volatile int nr_secunde = 50;
- volatile int minutes = 59;
- volatile int hours = 0;
- void setup() {
- TIMSK1 = (1 << TOIE1); // activare timer overflow
- TCCR1A = 0;
- TCCR1B = 0; // timer stop
- //activare INT0, INT1, PCINT20
- EIMSK = (1 << INT0);
- EIMSK |= (1 << INT1);
- //activare PCI2 (buton 3 - PCINT20 - PCI2)
- PCICR |= (1 << PCIE2);
- PCMSK2 |= (1 << PCINT20);
- //configurare LCD
- lcd.begin(16, 2);
- lcd.noCursor();
- }
- void loop() {
- lcd.setCursor(0, 1);
- if (hours < 10) lcd.print("0");
- lcd.print(hours);
- lcd.print("h");
- if (minutes < 10) lcd.print("0");
- lcd.print(minutes);
- lcd.print("m");
- if (nr_secunde < 10) lcd.print("0");
- lcd.print(nr_secunde);
- lcd.print("s");
- }
- ISR(TIMER1_OVF_vect) {
- TCNT1 = 0x0BDC;
- nr_secunde++;
- if (nr_secunde == 60) {
- nr_secunde = 0;
- minutes++;
- }
- if (minutes == 60) {
- minutes = 0;
- hours++;
- }
- }
- ISR(INT0_vect) {
- TCNT1 = 0x0BDC;
- TCCR1A = 0;
- TCCR1B = (1 << CS12); // timer start
- _delay_ms(400);
- }
- ISR(INT1_vect) {
- TCCR1A = 0;
- TCCR1B = 0; // timer stop
- _delay_ms(400);
- }
- ISR(PCINT2_vect) {
- nr_secunde = 0; //reset cronometru
- minutes = 0;
- hours = 0;
- _delay_ms(400);
- }
Advertisement
Add Comment
Please, Sign In to add comment