Untitled
unknown
plain_text
2 years ago
8.7 kB
8
Indexable
// 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>
#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