Untitled
unknown
plain_text
a year ago
8.8 kB
3
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>
int main(void) {
unsigned char portValue;
// Konfiguracja portów
AD1PCFG = 0xFFFF;
TRISA = 0x0000;
portValue = 0x00;
int program = 0;
unsigned char snakePosition = 0b00000111;
int direction = 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;
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++) {
unsigned char gray = i ^ (i >> 1);
LATA = gray;
__delay32(500000);
if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
}
break;
case 3:
for (int i = 255; i >= 0; i--) {
unsigned char gray = i ^ (i >> 1);
LATA = gray;
__delay32(500000);
if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
}
break;
case 4:
for (int i = 0; i <= 99; i++) {
unsigned char tens = i / 10;
unsigned char ones = i % 10;
LATA = (tens << 4) | ones;
__delay32(500000);
if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
}
break;
case 5:
for (int i = 99; i >= 0; i--) {
unsigned char tens = i / 10;
unsigned char ones = i % 10;
LATA = (tens << 4) | ones;
__delay32(500000);
if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
}
break;
case 6:
while(1) {
LATA = snakePosition;
__delay32(500000);
if (BUTTON_IsPressed(BUTTON_S4) || BUTTON_IsPressed(BUTTON_S3)) break;
if (snakePosition == 0b11100000) {
direction = -1;
} else if (snakePosition == 0b00000111) {
direction = 1;
}
if (direction == 1) {
snakePosition = (snakePosition << 1);
} else {
snakePosition = (snakePosition >> 1);
}
}
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:
{
unsigned char pseudo_random_seed = 0b1110011; // Inicjalizacja generatora pseudolosowego
while(1) {
for (int i = 0; i < 10; ++i) {
pseudo_random_seed = (pseudo_random_seed * 1103515245 + 12345) % 128; // Generowanie 6-bitowej liczby pseudolosowej
LATA = pseudo_random_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