Untitled

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


#define TOTAL_TIME_p1 (3) // w sekundach dla gracza 1
#define TOTAL_TIME_p2 (3) // w sekundach dla gracza 1

// Funkcja print wy?wietlaj?ca kolejne 8-bitowe znaki w p?tli while, * oznacza przypisanie nie warto?ci zmiennej lecz jej adresu.


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 (BUTTON_IsPressed ( BUTTON_S6 ) == true) {
                    zmiana = 3;
                }
            

            

            case 0:
            if(remainingSeconds_p1 < 1)
            {
                sprintf(buffer_p1, "%15s", "koniec czasu p1");
                LCD_ClearScreen();
                LCD_PutString(buffer_p1, strlen(buffer_p1));
                __delay32(4000000); //czekamy 10 sekund
                zmiana = 3;

            }else if(remainingSeconds_p2 < 1)
            {
                sprintf(buffer_p2, "%15s", "koniec czasu p2");
                LCD_ClearScreen();
                LCD_PutString(buffer_p2, strlen(buffer_p2));
                __delay32(4000000); //czekamy 10 sekund
                zmiana = 3;
            }


            case 1:

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

            unsigned char minutes_p1 = remainingSeconds_p1 / 60;
            unsigned char secs_p1 = remainingSeconds_p1 % 60;
            sprintf(buffer_p1, "%02u:%02u p1", minutes_p1, secs_p1); // zapis czasu do bufora
            // wyświetlenie na ekranie
            LCD_ClearScreen();
            LCD_PutString(buffer_p1, strlen(buffer_p1));
            __delay32(4000000); //czekamy sekundę
            remainingSeconds_p1--;
            
            if(remainingSeconds_p1 < 1)
            {
               zmiana = 0;
            }
            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 p2", 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--;
            
            if(remainingSeconds_p2 < 1)
            {
                zmiana = 0;
            }
            break;

            case 3:
                LCD_PutString("kto zaczyna     s3 = p1  s4 = p2",32);
                 __delay32(4000000);
                 LCD_ClearScreen();
                
                if (BUTTON_IsPressed ( BUTTON_S3 ) == true) {
                    zmiana = 1;
                    break;
                }
                if (BUTTON_IsPressed ( BUTTON_S4 ) == true) {
                    zmiana = 2;
                    break;
                }


            default:
                break;

    }
    }
    return 0;
}
Leave a Comment