当前位置:网站首页>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;
}
边栏推荐
- Pseudo static setting of access database in win2008 R2 iis7.5
- pycharm 查看opencv当前的版本
- Solution to invalid small program scroll into view
- PHP get (remote) large file method record
- What can QA do in a "de QA" project?
- Remote link software xshell and xftp download address
- 2022 JD 618 Comment rembourser le dépôt de pré - vente? Le dépôt JD 618 peut - il être remboursé?
- PHP Apple purchase verification steps
- CTF freshman cup PHP deserialization question - EzPop
- Download Notepad++
猜你喜欢

容器江湖的爱恨情仇
![[experiment] MySQL master-slave replication and read-write separation](/img/aa/7d0799013ff749cacf44ba3b773dff.png)
[experiment] MySQL master-slave replication and read-write separation

Fiddler automatically saves the result of the specified request to a file

CONDA install tensorflow test tensorflow

性能指标的信仰危机

2022淘宝618超级喵运会怎么玩?2022淘宝618喵运会玩法技巧

AcWing 41. 包含min函数的栈(单调栈)

On the improvement of 3dsc by harmonic shape context feature HSC

Malicious code analysis practice - lab06-01 exe~Lab06-04. Exe dynamic analysis

AcWing 132. 小组队列(队列模拟题)
随机推荐
Common tools download address
淺談調和形狀上下文特征HSC對3DSC的改進
Building 64 bit wampserver and DVWA in win7 virtual machine
PHP interface generates cache and MD5 encryption uniformly
Download Notepad++
Amélioration de la 3dsc par HSC
性能指标的信仰危机
Vscode code debugging skills
Leetcode 2169. Get operands of 0
Solution to the problem that the applet developer tool cannot input simplified Chinese
人脸识别pip 安装dlib库失败
The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time
Common methods of string class
2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills
PHP string encryption and decryption
Mobile terminal commissioning
深度学习与CV教程(14) | 图像分割 (FCN,SegNet,U-Net,PSPNet,DeepLab,RefineNet)
FPGA-按键实验
Get start date and end date for all quarters of the year
Global and local existence of array, integer and character variables