Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * "Hello World" example.
- *
- * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
- * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
- * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
- * device in your system's hardware.
- * The memory footprint of this hosted application is ~69 kbytes by default
- * using the standard reference design.
- *
- * For a reduced footprint version of this template, and an explanation of how
- * to reduce the memory footprint for a given application, see the
- * "small_hello_world" template.
- *
- */
- #include <stdio.h>
- #include "system.h"
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- #include "altera_avalon_pio_regs.h"
- int cont(int arr[], int n, int x);
- void CreateLED(int count);
- int BitCount(unsigned int u);
- long double diffclock(clock_t clock1, clock_t clock2);
- float MittelWert(float value[], int count);
- void CreateLED1(int count);
- void clrex();
- struct ranking
- {
- int index;
- char name[64];
- float time[1];
- };
- struct ranking table[2];
- int main()
- {
- //char dbug[2];
- printf("Hallo Willkommen zu diesem Shit!\n");
- // Integer for loop for 3 Persons
- int person = 0;
- for(person = 0; person < 3; person++)
- {
- // Spiel 1
- table[person].index = person;
- printf("Wie ist dein name?"); scanf("%s", table[person].name);
- printf("Willkomen %s.\n Dieses Nios II System beinhaltet 2 Spiele mit denen die Reaktionszeit gemessen wird.\n", table[person].name);
- int spiel1count = 0;
- float score[3];
- for(spiel1count = 0; spiel1count < 3; spiel1count++)
- {
- printf("Drücke eine taste um zu starten außer Enter");
- char s[1];
- scanf("%c", s);
- CreateLED(5);
- // scanf("%s",dbug);
- clock_t start = clock();
- while(IORD_ALTERA_AVALON_PIO_DATA(LEDR_BASE))
- {
- clock_t between = clock();
- long double a = diffclock(between, start);
- if(a > 3000)
- break;
- // Hier noch verbleibende Zeit auf 7 Segment ausgeben.
- int led=IORD_ALTERA_AVALON_PIO_DATA(LEDR_BASE);
- int sw=IORD_ALTERA_AVALON_PIO_DATA(SWITCHES_BASE);
- led=(led) & ~(sw);
- IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,led);
- }
- clock_t end = clock();
- printf("%Lf \n", diffclock(end, start));
- if(diffclock(end, start) > 3000)
- {
- }
- int led1=IORD_ALTERA_AVALON_PIO_DATA(LEDR_BASE);
- if(BitCount(led1) > 0)
- {
- // Berechnung
- score[spiel1count] = (5 - BitCount(led1)) / 3;
- }
- else if(BitCount(led1) == 0)
- {
- score[spiel1count] = 5/3;
- }
- printf("Spiel %d beendet. \n Bitte schalte alle Switches wieder aus.", spiel1count);
- }
- table[person].time[0] = MittelWert(score, 3);
- // Spiel 2
- int spiel2count = 0;
- float score2[10];
- printf("Drücke eine taste um zu starten außer Enter");
- char s1[1];
- scanf("%c", s1);
- for(spiel2count = 0; spiel2count < 10; spiel2count++)
- {
- CreateLED1(1);
- clock_t start1 = clock();
- while(IORD_ALTERA_AVALON_PIO_DATA(LEDR_BASE))
- {
- // Hier noch verbleibende Zeit auf 7 Segment ausgeben.
- int led=IORD_ALTERA_AVALON_PIO_DATA(LEDR_BASE);
- int sw=IORD_ALTERA_AVALON_PIO_DATA(SWITCHES_BASE);
- led=(led) & ~(sw);
- IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,led);
- }
- clock_t end1 = clock();
- printf("%Lf \n", diffclock(end1, start1));
- score2[spiel2count] = diffclock(end1, start1);
- printf("Spiel %d beendet", spiel2count);
- }
- table[person].time[1] = MittelWert(score2, 10);
- }
- printf("Programm fertig!!!");
- return 0;
- }
- int cont(int arr[], int n, int x)
- {
- while (n--)
- {
- if (arr[n] == x) return 1;
- }
- return 0;
- }
- void CreateLED(int count)
- {
- int exsp[count];
- srand(time(NULL));
- int i = 0;
- for (i = 0; i < count; i++)
- {
- do {
- exsp[i] = rand() % 18;
- } while (cont(exsp, i, exsp[i]));
- }
- float dez=0;
- int n = 0;
- for(n = 0; n < count; n++)
- {
- printf("%d\n",exsp[n]);
- dez += pow(2, exsp[n]);
- }
- IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE, (int)dez);
- }
- int exsp1[10];
- void clrex()
- {
- int i = 0;
- for(i = 0; i < sizeof(exsp1); i++)
- {
- exsp1[i] = 0;
- }
- }
- int b = 0;
- void CreateLED1(int count)
- {
- srand(time(NULL));
- int i = 0;
- for (i = 0; i < count; i++)
- {
- do {
- exsp1[b] = rand() % 18;
- } while (cont(exsp1, b, exsp1[b]));
- }
- float dez=0;
- int n = 0;
- for(n = 0; n < count; n++)
- {
- printf("%d\n",exsp1[n]);
- dez += pow(2, exsp1[n]);
- }
- b++;
- IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE, (int)dez);
- }
- //Counts 1's in a unsigned int
- int BitCount(unsigned int u)
- {
- int count = 0;
- int i = 0;
- for(i = 0; i < 18; i++)
- {
- if (u % 2 == 1)
- {
- count++;
- }
- u = u >> 1;
- }
- return count;
- }
- // Diffrence between Clocks in Milliseconds
- long double diffclock(clock_t clock1, clock_t clock2)
- {
- double diffticks = clock1 - clock2;
- double diffms = (diffticks) / (CLOCKS_PER_SEC / 1000);
- return diffms;
- }
- float MittelWert(float value[], int count)
- {
- float t = 0;
- int i = 0;
- for(i = 0; i < count; i++)
- {
- t += value[i];
- }
- return t / count;
- }
- void sevenseg_set_hex(int hex, char segment[])
- {
- static alt_u8 segments[16] = {
- 0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, /* 0-9 */
- 0x88, 0xE0, 0xF2, 0xC2, 0xB0, 0xB8 }; /* a-f */
- unsigned int data = segments[hex & 15] | (segments[(hex >> 4) & 15] << 8);
- IOWR_ALTERA_AVALON_PIO_DATA(segment, data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement