Untitled

 avatar
unknown
plain_text
a year ago
1.5 kB
6
Indexable
#include <xc.h>
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
#include "buttons.h"

// Stałe
#define TOTAL_TIME (300) // Totalny czas w sekundach

int main(void) {
    // Zmienne
    char buffer[16];                 // Bufor na znaki do wyswietlenia
    unsigned int remainingSeconds = TOTAL_TIME;

    // Inicjalizacja
    LCD_Initialize();                // Inicjalizacja LCD 

    // Główna pętla
    while (remainingSeconds > 1) {
        // Obsługa przycisków
        if (BUTTON_IsPressed(BUTTON_S3) == true) {
            remainingSeconds += 30;  // Dodaj 30 sekund po naciśnięciu S3
        } else if (BUTTON_IsPressed(BUTTON_S4) == true) {
            remainingSeconds -= 30;  // Odejmij 30 sekund po naciśnięciu S4
        }

        // Formatowanie czasu do wyświetlenia
        unsigned char minutes = remainingSeconds / 60;
        unsigned char secs = remainingSeconds % 60;
        sprintf(buffer, "%02u:%02u", minutes, secs);

        // Wyswietlenie
        LCD_ClearScreen();
        LCD_PutString(buffer, strlen(buffer));
        __delay32(4000000); // Odczekaj 1 sekundę
        remainingSeconds--; // Odlicz jedną sekundę
    }

    // Komunikat o końcu czasu
    sprintf(buffer, "%12s", "koniec czasu"); 
    LCD_ClearScreen();
    LCD_PutString(buffer, strlen(buffer));
    __delay32(40000000); // Odczekaj 10 sekund

    return 0;
}
Editor is loading...
Leave a Comment