Untitled

 avatar
unknown
plain_text
a year ago
7.6 kB
8
Indexable
#include "buttons.h"

#include <math.h>

#include <xc.h>

#include <stdlib.h>

#include <time.h> // Dodaj bibliotek? time.h

unsigned char kodg(unsigned char num) {
    return num ^ (num >> 1);
}

int main(void) {

    unsigned char portValue;

    // Konfiguracja portów

    AD1PCFG = 0xFFFF;

    TRISA = 0x0000;

    portValue = 0x00;

    int program = 0;

    unsigned char wezyk = 0b00000111;
    int kierunek = 1;



    unsigned char wynik = 0;
    unsigned char pomoc = 1;
    unsigned char pomoc2 = 1;
    unsigned char pomoc3 = 1;
    unsigned char pomoc4 = 1;
    unsigned char pomoc5 = 1;
    unsigned char pomoc6 = 1;
    unsigned char pomoc7 = 1;

    unsigned int stan = 0b1110011;


    unsigned char podstawowy_seed = 0b1110011; // Inicjalizacja generatora pseudolosowego

    while(1){

        if(BUTTON_IsPressed(BUTTON_S3)){

            if(program==0){

                program=9;

            }else{

                program--;

                __delay32(1500000);

            }

        }

        if(BUTTON_IsPressed(BUTTON_S4)){

            if(program==9){

                program=0;

            }else{

                program++;

                __delay32(1500000);

            }

        }

        switch(program){

            case 0:

                for(int i=0;i<=255;i++){

                    LATA = i;

                    __delay32(500000);

                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                }

                break;

            case 1:

                for(int i=255;i>=0;i--){

                    LATA = i;

                    __delay32(500000);

                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                }

                break;

            case 2:

                for (int i = 0; i <= 255; i++) {

                    LATA = i ^ (i >> 1);

                    __delay32(500000);

                    if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                }

                break;

            case 3:

                for (int i = 255; i >= 0; i--) {

                    LATA = i ^ (i >> 1);

                    __delay32(500000);

                    if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                }

                break;

            case 4:

                for (int i = 0; i <= 99; i++) {
                    int value_to_set = ((i / 10) << 4) | (i % 10);
                    LATA = value_to_set;
                    __delay32(500000);
                    if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
                }


                break;

            case 5:

                for (int i = 99; i >= 0; i--) {

                    int value_to_set = ((i / 10) << 4) | (i % 10);
                    LATA = value_to_set;
                    __delay32(500000);

                    if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                }

                break;

            case 6:

                while (1) {

                    LATA = wezyk;
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    if ((wezyk == 0b00000111 && kierunek == -1) || (wezyk == 0b11100000 && kierunek == 1))
                        kierunek *= -1;
                    wezyk = (kierunek == 1) ? (wezyk << 1) : (wezyk >> 1);
                    __delay32(1500000);


                }

                break;

            case 7:
                while(1){
                    for(int i = 0;i < 7;i++){
                        wynik = pomoc;
                        pomoc = pomoc << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 6;i++){
                        wynik = pomoc + pomoc2;
                        pomoc2 = pomoc2 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 5;i++){
                        wynik = pomoc + pomoc2 + pomoc3;
                        pomoc3 = pomoc3 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 4;i++){
                        wynik = pomoc + pomoc2 + pomoc3 + pomoc4;
                        pomoc4 = pomoc4 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 3;i++){
                        wynik = pomoc + pomoc2 + pomoc3 + pomoc4 + pomoc5;
                        pomoc5 = pomoc5 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }

                    for(int i = 0;i < 2;i++){
                        wynik = pomoc + pomoc2 + pomoc3 + pomoc4 + pomoc5 + pomoc6;
                        pomoc6 = pomoc6 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 1;i++){
                        wynik = pomoc + pomoc2 + pomoc3 + pomoc4 + pomoc5 + pomoc6 + pomoc7;
                        pomoc7 = pomoc7 << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    wynik = wynik + 1;
                    __delay32(500000);
                    LATA = wynik;

                    wynik = wynik + 1;
                    __delay32(500000);
                    LATA = wynik;


                    wynik = 0;
                    pomoc = 1;
                    pomoc2 = 1;
                    pomoc3 = 1;
                    pomoc4 = 1;
                    pomoc5 = 1;
                    pomoc6 = 1;
                    pomoc7 = 1;



                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
                }
                break;

            case 8:
            {

                while(1) {
                    for (int i = 0; i < 10; ++i) {
                        podstawowy_seed = (podstawowy_seed * 1103515245 + 12345) % 128; // Generowanie 6-bitowej liczby pseudolosowej
                        LATA = podstawowy_seed; // Ustawienie portu LATA na wygenerowan? warto?? pseudolosow?
                        __delay32(1500000);
                        if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
                }
            }
                break;

            default:

                break;

        }

    }

    return -1;

}
Editor is loading...
Leave a Comment