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 <io.h>
- #include <system.h>
- #define SEGA 0x00001
- #define SEGB 0x00002
- #define SEGC 0x00004
- #define SEGD 0x00008
- #define SEGE 0x00010
- #define SEGF 0x00020
- #define SEGG 0x00040
- int main()
- {
- printf("Hello from Nios II!\n");
- int sw = 0; // stan sliderow
- int S[5] = {0}; // pokoje licznik osob
- int Sb[5] = {0}; // pokoje stan swiatla 1-zaplone 0-zgaszone
- int light = 0; // przechowuje stan ledow
- short state = 0; // przechowuje pushbuttony PB nr.4 stan 1- z mniej do wiekszego pokoju (wchodzenie) 0- z wieksz do mniej(wychodzenie)
- //int CD[10] = {0}; // wejscia
- int swFlag = 0; // flaga sprawdza, czy switch jest wlaczony czy nie
- int errFlag = 0; // sprawdza czy jest wiecej niz 1 slider wlacozny
- int errLED = 0;
- int HEXDsp = 0; // przechowuje HEX Display
- int osoby[5] = {0}; // tablica przechowuje il.osob -> HEDDisplay
- int i; // index
- while(1){
- if(state == IORD(PUSHBUTTON_BASE, 0)){
- state = 0; // wychodzenie
- }
- else
- state = 1; // wchodzenie
- sw = IORD(SW_SLIDERS_BASE, 0);
- if(swFlag == 0){
- switch (sw) {
- case 0:
- break;
- case 1:
- printf("Drzwi 1\n");
- if(state)
- S[4]++;
- else if(S[4]<1){
- errFlag = 1;
- printf("Error Drzwi 1\n");
- }
- else
- S[4]--;
- swFlag = 1;
- break;
- case 2:
- printf("Drzwi 2\n");
- if(state)
- S[0]++;
- else if(S[0] < 1){
- errFlag = 1;
- printf("Error Drzwi 2\n");
- }
- else
- S[0]--;
- swFlag = 1;
- break;
- case 4:
- printf("Drzwi 3\n");
- if(state)
- S[2]++;
- else if(S[2] < 1){
- errFlag = 1;
- printf("Error Drzwi 3\n");
- }
- else
- S[2]--;
- swFlag = 1;
- break;
- case 8:
- printf("Drzwi 4\n");
- if(state){ // s0 -> s2
- if(S[0] < 1){
- errFlag = 1;
- printf("Error Drzwi 4\n");
- }
- else{
- S[0]--;
- S[2]++;
- }
- }
- else{ //s2 -> s0
- if(S[2] < 1){
- errFlag = 1;
- printf("Error Drzwi 4\n");
- }
- else{
- S[2]--;
- S[0]++;
- }
- }
- swFlag = 1;
- break;
- case 16:
- printf("Drzwi 5\n");
- if(state){ // s0 -> s4
- if(S[0] < 1){
- errFlag = 1;
- printf("Error Drzwi 5\n");
- }
- else{
- S[0]--;
- S[4]++;
- }
- }
- else{ //s4 -> s0
- if(S[4] < 1){
- errFlag = 1;
- printf("Error Drzwi 5\n");
- }
- else{
- S[4]--;
- S[0]++;
- }
- }
- swFlag = 1;
- break;
- case 32:
- printf("Drzwi 6\n");
- if(state){ // s3 -> s4
- if(S[3] < 1){
- errFlag = 1;
- printf("Error Drzwi 6\n");
- }
- else{
- S[3]--;
- S[4]++;
- }
- }
- else{ //s4 -> s3
- if(S[4] < 1){
- errFlag = 1;
- printf("Error Drzwi 6\n");
- }
- else{
- S[4]--;
- S[3]++;
- }
- }
- swFlag = 1;
- break;
- case 64:
- printf("Drzwi 7\n");
- if(state)
- S[3]++;
- else if(S[3] < 1){
- errFlag = 1;
- printf("Error Drzwi 7\n");
- }
- else
- S[3]--;
- swFlag = 1;
- break;
- case 128:
- printf("Drzwi 8\n");
- if(state)
- S[7]++;
- else if(S[7] < 1){
- errFlag = 1;
- printf("Error Drzwi 8\n");
- }
- else
- S[7]--;
- swFlag = 1;
- break;
- case 256:
- printf("Drzwi 9\n");
- if(state)
- S[8]++;
- else if(S[8] < 1){
- errFlag = 1;
- printf("Error Drzwi 9\n");
- }
- else
- S[8]--;
- swFlag = 1;
- break;
- case 512:
- printf("Drzwi 10\n");
- if(state){ // s1-> s3
- if(S[1] < 1){
- errFlag = 1;
- printf("Error Drzwi 6\n");
- }
- else{
- S[1]--;
- S[3]++;
- }
- }
- else{ //s3 -> s1
- if(S[3] < 1){
- errFlag = 1;
- printf("Error Drzwi 6\n");
- }
- else{
- S[3]--;
- S[1]++;
- }
- }
- swFlag = 1;
- break;
- default:
- printf("Error 2 slidery wlaczone");
- errFlag = 1;
- swFlag = 1;
- break;
- }
- }
- else if(sw == 0){ // slidery sa na OFF
- swFlag = 0;
- if(errFlag){
- errFlag = 0;
- //S[] = 0 // dopsiac petle for
- }
- }
- //----------- ilosc osob na swiatlo
- if(S[0] > 0)
- Sb[0] = 1;
- else
- Sb[0] = 0;
- if(S[1] > 0)
- Sb[1] = 2;
- else
- Sb[1] = 0;
- if(S[2] > 0)
- Sb[2] = 4;
- else
- Sb[2] = 0;
- if(S[3] > 0)
- Sb[3] = 8;
- else
- Sb[3] = 0;
- if(S[4] > 0)
- Sb[4] = 16;
- else
- Sb[4] = 0;
- if(errFlag)
- errLED = 0b1000000000; //512?
- else
- errLED = 0;
- //------------------- zapalanie LEDow
- light = errLED + Sb[0] + Sb[1] + Sb[2] + Sb[3] +Sb[4];
- //printf("%d\n", light);
- IOWR(LEDS_BASE,0,light);
- }
- //------------------- HEXY
- if(errFlag = 0){
- for(i=0; i< 5; i++){
- switch(S[i]){
- case 0:
- osoby[i] = SEGA | SEGB | SEGC | SEGD | SEGE | SEGF;
- break;
- case 1:
- osoby[i] = SEGB | SEGC;
- break;
- case 2:
- osoby[i] = SEGA | SEGB | SEGD | SEGE | SEGG;
- break;
- case 3:
- osoby[i] = SEGA | SEGB | SEGC | SEGD | SEGG;
- break;
- case 4:
- osoby[i] = SEGB | SEGC | SEGF | SEGG;
- break;
- case 5:
- osoby[i] = SEGA | SEGF | SEGG | SEGC | SEGD;
- break;
- case 6:
- osoby[i] = SEGA | SEGC | SEGD | SEGE | SEGF | SEGG;
- break;
- case 7:
- osoby[i] = SEGA | SEGB | SEGC;
- break;
- case 8:
- osoby[i] = SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG;
- break;
- case 9:
- osoby[i] = SEGA | SEGB | SEGC | SEGD | SEGF | SEGG;
- break;
- default:
- osoby[i] = SEGG; // jezeli >9 to wyswietla -
- break;
- }
- }
- }
- else{ // ERROR
- osoby[4] = SEGA | SEGD | SEGE | SEGF | SEGG; // E
- osoby[3] = SEGE | SEGG; // r
- osoby[2] = SEGE | SEGG; // r
- osoby[1] = SEGC | SEGD | SEGE | SEGG; // o
- osoby[0] = SEGE | SEGG; // r
- }
- HEXDsp = osoby[0] | (osoby[1] << 7) | (osoby[2] << 14) | (osoby[3] << 21) | (osoby[4] << 28);
- IOWR(HEX_BASE,0,HEXDsp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement