Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.2 kB
3
Indexable
Never
#include <xc.h>
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
#include "buttons.h"

#define TOTAL_TIME_p1 (300) // w sekundach dla gracza 1
#define TOTAL_TIME_p2 (300) // w sekundach dla gracza 1
volatile unsigned int seconds_p1 = TOTAL_TIME_p1;
volatile unsigned int seconds_p2 = TOTAL_TIME_p2;

int main(void) {

    char buffer_p1[16]; // bufor na znaki do wyświetlenia na ekranie
    char buffer_p2[16]; // bufor na znaki do wyświetlenia na ekranie
    LCD_Initialize(); // inicjalizacja LCD
    unsigned int remainingSeconds_p1 = seconds_p1;
    unsigned int remainingSeconds_p2 = seconds_p2;
    int zmiana = 3;

    while(true){
        switch(zmiana){

            if(remainingSeconds_p1 > 1)
            {
               zmiana = 0;
            }else if(remainingSeconds_p2 > 1)
            {
                zmiana = 0;
            }

            case 0:
            if(remainingSeconds_p1 > 1)
            {
                sprintf(buffer, "%15s", "koniec czasu p1");
                LCD_ClearScreen();
                LCD_PutString(buffer_1, strlen(buffer_1));
                __delay32(40000000); //czekamy 10 sekund

            }else if(remainingSeconds_p2 > 1)
            {
                sprintf(buffer, "%15s", "koniec czasu p2");
                LCD_ClearScreen();
                LCD_PutString(buffer_2, strlen(buffer_2));
                __delay32(40000000); //czekamy 10 sekund
            }


            case 1:

                if (BUTTON_IsPressed ( BUTTON_S3 ) == true) {
                    remainingSeconds_p1 = remainingSeconds_p1 + 2;
                    zmiana = 2;
                    break;
                }

            unsigned char minutes = remainingSeconds_p1 / 60;
            unsigned char secs = remainingSeconds_p1 % 60;
            sprintf(buffer_p1, "%02u:%02u", minutes, secs); // zapis czasu do bufora
            // wyświetlenie na ekranie
            LCD_ClearScreen();
            LCD_PutString(buffer_p1, strlen(buffer_p1));
            __delay32(4000000); //czekamy sekundę
            remainingSeconds_p1--;

            break;


            case 2:

                if (BUTTON_IsPressed ( BUTTON_S4 ) == true) {
                    remainingSeconds_p2 = remainingSeconds_p2 + 2;
                    zmiana = 1;
                    break;
                }

            unsigned char minutes = remainingSeconds_p2 / 60;
            unsigned char secs = remainingSeconds_p2 % 60;
            sprintf(buffer_p2, "%02u:%02u", minutes, secs); // zapis czasu do bufora
            // wyświetlenie na ekranie
            LCD_ClearScreen();
            LCD_PutString(buffer_p2, strlen(buffer_p2));
            __delay32(4000000); //czekamy sekundę
            remainingSeconds_p2--;
            break;

            case 3:
                if (BUTTON_IsPressed ( BUTTON_S3 ) == true) {

                    break;
                }
                if (BUTTON_IsPressed ( BUTTON_S4 ) == true) {

                    break;
                }


            default:
                break;

    }
    return 0;
}
Leave a Comment