Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2018 Matej "B-Matt" Arlović.
- * All rights reserved.
- * WEB: https://gas-locator.com
- */
- #include <stdio.h>
- #include "platform.h"
- #include "xparameters.h"
- #include "xgpio.h"
- #define LED_1 0x01
- #define LED_2 0x02
- #define LED_3 0x04
- #define LED_4 0x08
- #define LED_5 0x10
- #define LED_6 0x20
- #define LED_7 0x40
- #define LED_8 0x80
- #define PUSH_1 0x1
- #define PUSH_2 0x2
- #define PUSH_3 0x4
- #define PUSH_4 0x8
- void print(char *str);
- int main()
- {
- init_platform();
- XGpio switchesGpio, ledsGpio, pushGpio;
- XGpio_Initialize(&switchesGpio, XPAR_DIP_SWITCHES_8BITS_DEVICE_ID);
- XGpio_Initialize(&pushGpio, XPAR_PUSH_DEVICE_ID);
- XGpio_Initialize(&ledsGpio, XPAR_LEDS_DEVICE_ID);
- XGpio_SetDataDirection(&switchesGpio, 1, 0xff);
- XGpio_SetDataDirection(&pushGpio, 1, 0xff);
- XGpio_SetDataDirection(&ledsGpio, 1, 0x0);
- int i = 0;
- int runingLeds = 0;
- int runingLedsMin = 255;
- int runingLeds2 = 1;
- while(1)
- {
- u32 pushData = XGpio_DiscreteRead(&pushGpio, 1);
- if(pushData)
- {
- if(pushData & PUSH_1)
- {
- XGpio_DiscreteSet(&ledsGpio, 1, (LED_1 | LED_3 | LED_5 | LED_7));
- for(i=0; i < 1000000; i++);
- XGpio_DiscreteClear(&ledsGpio, 1, (LED_1 | LED_3 | LED_5 | LED_7));
- }
- else if(pushData & PUSH_2)
- {
- XGpio_DiscreteWrite(&ledsGpio, 1, runingLeds);
- runingLeds += 1;
- if(runingLeds >= 255)
- runingLeds = 0;
- for(i=0; i < 100000; i++);
- }
- else if(pushData & PUSH_3)
- {
- XGpio_DiscreteWrite(&ledsGpio, 1, runingLedsMin);
- runingLedsMin /= 2;
- if(runingLedsMin <= 0)
- runingLedsMin = 255;
- for(i=0; i < 1000000; i++);
- }
- else if(pushData & PUSH_4)
- {
- XGpio_DiscreteWrite(&ledsGpio, 1, runingLeds2);
- runingLeds2 *= 2;
- if(runingLeds2 >= 255)
- runingLeds2 = 1;
- for(i=0; i < 1000000; i++);
- }
- }
- else
- {
- u32 switchData = XGpio_DiscreteRead(&switchesGpio, 1);
- XGpio_DiscreteWrite(&ledsGpio, 1, switchData);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement