当前位置:网站首页>FPGA key experiment
FPGA key experiment
2022-06-12 10:38:00 【Lemon with pure milk】
#include <stdio.h>
#include "platform.h"
#include "xparameters.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xgpio.h"
#include <unistd.h> // usleep() Delay function header file
#include <stdbool.h> // bool
#define LED_DEVICE_ID XPAR_AXI_GPIO_1_DEVICE_ID
#define KEY_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_ID
XGpio LEDInst;
XGpio KEYInst;
u8 key_value_pre=0;
u8 key_value_now=0;
int main()
{
init_platform();
int status;
// initialization
status = XGpio_Initialize(&KEYInst, KEY_DEVICE_ID); // initial KEY
/*int XGpio_Initialize(XGpio * InstancePtr, u16 DeviceId)
* function : initialization XGpio example .
* Parameters 1: Pointer to the device instance .
* Parameters 2: equipment ID.
* return : Successfully returns XST_SUCCESS, Failure to return XST_DEVICE_NOT_FOUND */
if(status != XST_SUCCESS)
// After calling the above function, judge whether the initialization is successful according to the return value , If status It's not equal to XST_SUCCESS Failure
return XST_FAILURE;
status = XGpio_Initialize(&LEDInst, LED_DEVICE_ID); // initial LED
if(status != XST_SUCCESS)
return XST_FAILURE;
// The configuration phase
XGpio_SetDataDirection(&KEYInst, 1, 1); // set KEY IO direction as in
/*void XGpio_SetDataDirection(XGpio * InstancePtr, unsigned Channel,u32 DirectionMask)
* function : Set the input / output direction of each channel .
* Parameters 1: Pointer to the device instance .
* Parameters 2: Ready for operation GPIO The passage of (Vivado Set in gpio IP Setting channel of , by 1 or 2).
* Parameters 3: Mask that determines the direction of input and output ,1 An input 0 For export .
*/
XGpio_SetDataDirection(&LEDInst, 1, 0); // set LED IO direction as out, Set the lamp to output
XGpio_DiscreteWrite(&LEDInst, 1, 0x0);// at initial, all LED turn off
/*void XGpio_DiscreteWrite(XGpio * InstancePtr, unsigned Channel, u32 Data)
* function : Write input data to the input device instance .
* Parameters 1: Examples of equipment
* Parameters 2: passageway
* Parameters 3: The data to be written
* return : void*/
printf(">>> Press PL KEY1 ~ KEY4 one by one, and check the PL LED1 ~ LED4\n");
// Actual program execution stage
while(1)
{
usleep(100000); // 0.1s sleep, to debounce, in common, the meta-state will sustain no more than 20ms
/*usleep The command is used to delay time in microseconds
*1 second =1000 millisecond =1000,000 Microsecond =1000,000,000 nanosecond .
* Commonly used way
* Format :usleep <us>
* Delay <us> Microsecond .*/
key_value_pre=key_value_now;
key_value_now= XGpio_DiscreteRead(&KEYInst, 1) & 0x0F;
/* u32 XGpio_DiscreteRead(XGpio * InstancePtr, unsigned Channel)
* function : Read current IO state .
* Parameters 1: Device instance pointer .
* Parameters 2: passageway .
* return :IO Current value .*/
XGpio_DiscreteWrite(&LEDInst, 1, key_value_now);
if(key_value_pre!=key_value_now)
printf("key state_changed!\n");
}
cleanup_platform();
return 0;
}
边栏推荐
- file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
- Get array median
- 分布式存储探索
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- Get all listening events in the element
- MQTT 协议中文版
- PHP interface generates cache and MD5 encryption uniformly
- Principle analysis of vite HMR
- 力扣(LeetCode)162. 寻找峰值(2022.06.11)
- PHP uses RSA segment encryption and decryption method
猜你喜欢

AcWing 131. 直方图中最大的矩形(单调栈经典运用 模板)

Pycharm view the current version of opencv

数组,整型,字符变量在全局和局部的存在形式

Malicious code analysis practice - lab03-01 Exe basic dynamic analysis

Love and hate in the Jianghu

2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills

ArrayList automatic capacity expansion principle

基于QT的旅行查询与模拟系统
![[experiment] MySQL master-slave replication and read-write separation](/img/aa/7d0799013ff749cacf44ba3b773dff.png)
[experiment] MySQL master-slave replication and read-write separation

淺談調和形狀上下文特征HSC對3DSC的改進
随机推荐
PHP can load different new data methods for each refresh
M-Arch(番外13)GD32L233评测-来点音乐
Chapter 3 search
How to upload the video on the computer to the mobile phone without network
JS scale down the width and height of the picture
Common port description
Malicious code analysis practice - lab03-02 DLL analysis
A hundred secrets and a few secrets - Caesar encryption
Machine learning is not something you can use if you want to use it
Collation of common functions in JS
Php:redis uses geospatial
2022淘宝618超级喵运会怎么玩?2022淘宝618喵运会玩法技巧
深度学习与CV教程(14) | 图像分割 (FCN,SegNet,U-Net,PSPNet,DeepLab,RefineNet)
Remote link software xshell and xftp download address
Amélioration de la 3dsc par HSC
Malicious code analysis practice - use IDA pro to analyze lab05-01 dll
PHP specifies the number of people to distribute the specified amount equally at random (scaling method)
Create vite source code analysis
2022 JD 618 Comment rembourser le dépôt de pré - vente? Le dépôt JD 618 peut - il être remboursé?
M-Arch(番外12)GD32L233评测-CAU加解密(捉弄下小编)