Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
8.4 kB
2
Indexable
Never
// PIC24FJ128GA010 Configuration Bit Settings

// For more on Configuration Bits

// consult your device data sheet

// CONFIG2

#pragma config POSCMOD = XT // XT Oscillator mode selected

#pragma config OSCIOFNC = ON // OSC2/CLKO/RC15 as port I/O (RC15)

#pragma config FCKSM = CSDCMD // Clock Switching and Monitor disabled

#pragma config FNOSC = PRI // Primary Oscillator (XT, HS, EC)

#pragma config IESO = ON // Int Ext Switch Over Mode enabled

// CONFIG1

#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)

#pragma config FWPSA = PR128 // WDT Prescaler (1:128)

#pragma config WINDIS = ON // Watchdog Timer Window Mode disabled

#pragma config FWDTEN = OFF // Watchdog Timer disabled

#pragma config ICS = PGx2 // Emulator/debugger uses EMUC2/EMUD2

#pragma config GWRP = OFF // Writes to program memory allowed

#pragma config GCP = OFF // Code protection is disabled

#pragma config JTAGEN = OFF // JTAG port is disabled

// #pragma config statements should precede project file includes.

// Use project enums instead of #define for ON and OFF.

#include "buttons.h"

#include <math.h>

#include <xc.h>

#include <stdlib.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 pom = 1;
    unsigned char pom2 = 1;
    unsigned char pom3 = 1;
    unsigned char pom4 = 1;
    unsigned char pom5 = 1;
    unsigned char pom6 = 1;
    unsigned char pom7 = 1;

    unsigned int stan = 0b1110011;

    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 = pom;
                        pom = pom << 1;
                        __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

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

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

                    for(int i = 0;i < 4;i++){
                        wynik = pom + pom2 + pom3 + pom4;
                        pom4 = pom4 << 1;
                         __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 3;i++){
                        wynik = pom + pom2 + pom3 + pom4 + pom5;
                        pom5 = pom5 << 1;
                         __delay32(500000);
                        LATA = wynik;
                    }

                    for(int i = 0;i < 2;i++){
                        wynik = pom + pom2 + pom3 + pom4+ pom5 + pom6;
                        pom6 = pom6 << 1;
                         __delay32(500000);
                        LATA = wynik;
                    }
                    if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;

                    for(int i = 0;i < 1;i++){
                        wynik = pom + pom2 + pom3 + pom4+ pom5 + pom6 + pom7;
                        pom7 = pom7 << 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;
                       pom = 1;
                       pom2 = 1;
                       pom3 = 1;
                       pom4 = 1;
                       pom5 = 1;
                       pom6 = 1;
                       pom7 = 1;
                        


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

            case 8:
                
                while(1)
                {
                        for (int i = 0; i < 10; ++i) {
                         
                        stan = rand() % 255;
                        LATA = stan;
                        __delay32(1500000);
                        if(BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
                        
        }
                }

                break;

            default:

                break;

        }

    }

    return -1;

    }
Leave a Comment