Advertisement
B-Matt

Microblaze Application - Switches, Pushes & LEDs

Apr 24th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2018 Matej "B-Matt" Arlović.  
  3.  * All rights reserved.
  4.  * WEB: https://gas-locator.com
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "platform.h"
  9. #include "xparameters.h"
  10. #include "xgpio.h"
  11.  
  12. #define LED_1 0x01
  13. #define LED_2 0x02
  14. #define LED_3 0x04
  15. #define LED_4 0x08
  16. #define LED_5 0x10
  17. #define LED_6 0x20
  18. #define LED_7 0x40
  19. #define LED_8 0x80
  20.  
  21. #define PUSH_1 0x1
  22. #define PUSH_2 0x2
  23. #define PUSH_3 0x4
  24. #define PUSH_4 0x8
  25.  
  26. void print(char *str);
  27.  
  28. int main()
  29. {
  30.     init_platform();
  31.     XGpio switchesGpio, ledsGpio, pushGpio;
  32.     XGpio_Initialize(&switchesGpio, XPAR_DIP_SWITCHES_8BITS_DEVICE_ID);
  33.     XGpio_Initialize(&pushGpio, XPAR_PUSH_DEVICE_ID);
  34.     XGpio_Initialize(&ledsGpio, XPAR_LEDS_DEVICE_ID);
  35.  
  36.     XGpio_SetDataDirection(&switchesGpio, 1, 0xff);
  37.     XGpio_SetDataDirection(&pushGpio, 1, 0xff);
  38.     XGpio_SetDataDirection(&ledsGpio, 1, 0x0);
  39.  
  40.     int i = 0;
  41.     int runingLeds = 0;
  42.     int runingLedsMin = 255;
  43.     int runingLeds2 = 1;
  44.  
  45.     while(1)
  46.     {
  47.         u32 pushData = XGpio_DiscreteRead(&pushGpio, 1);
  48.         if(pushData)
  49.         {
  50.             if(pushData & PUSH_1)
  51.             {
  52.                 XGpio_DiscreteSet(&ledsGpio, 1, (LED_1 | LED_3 | LED_5 | LED_7));
  53.                 for(i=0; i < 1000000; i++);
  54.                 XGpio_DiscreteClear(&ledsGpio, 1, (LED_1 | LED_3 | LED_5 | LED_7));
  55.             }
  56.             else if(pushData & PUSH_2)
  57.             {
  58.                 XGpio_DiscreteWrite(&ledsGpio, 1, runingLeds);
  59.                 runingLeds += 1;
  60.                 if(runingLeds >= 255)
  61.                     runingLeds = 0;
  62.                 for(i=0; i < 100000; i++);
  63.             }
  64.             else if(pushData & PUSH_3)
  65.             {
  66.                 XGpio_DiscreteWrite(&ledsGpio, 1, runingLedsMin);
  67.                 runingLedsMin /= 2;
  68.                 if(runingLedsMin <= 0)
  69.                     runingLedsMin = 255;
  70.                 for(i=0; i < 1000000; i++);
  71.             }
  72.             else if(pushData & PUSH_4)
  73.             {
  74.                 XGpio_DiscreteWrite(&ledsGpio, 1, runingLeds2);
  75.                 runingLeds2 *= 2;
  76.                 if(runingLeds2 >= 255)
  77.                     runingLeds2 = 1;
  78.                 for(i=0; i < 1000000; i++);
  79.             }
  80.         }
  81.         else
  82.         {
  83.             u32 switchData = XGpio_DiscreteRead(&switchesGpio, 1);
  84.             XGpio_DiscreteWrite(&ledsGpio, 1, switchData);
  85.         }
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement