当前位置:网站首页>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;
}
边栏推荐
- M-Arch(番外11)GD32L233评测-PWM驱动有源蜂鸣器
- A few secrets - a special day
- 2022 JD 618 Comment rembourser le dépôt de pré - vente? Le dépôt JD 618 peut - il être remboursé?
- MYSQL——内置函数
- PHP string encryption and decryption
- [experiment] MySQL master-slave replication and read-write separation
- 使用cpolar远程办公(2)
- PHP: Excel to get the letter header
- PHP specifies the number of people to distribute the specified amount equally at random (scaling method)
- Is the acceptance standard a test case?
猜你喜欢

分布式存储探索

A hundred secrets and a few secrets - Caesar encryption

A snare - Cookie spoofing

Leetcdoe 2037. Make each student have the minimum number of seat movements (yes, once)

人脸识别pip 安装dlib库失败

Set SVG color

Building 64 bit wampserver and DVWA in win7 virtual machine

2022淘宝618超级喵运会玩法来了 超级喵运会有哪些攻略方法

Create vite source code analysis

机器学习不是你想用,想用就能用
随机推荐
CTF freshman cup PHP deserialization question - EzPop
Pycharm view the current version of opencv
Get array median
This and final keywords
CONDA install tensorflow test tensorflow
PHP interface generates cache and MD5 encryption uniformly
file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
淺談調和形狀上下文特征HSC對3DSC的改進
PHP curl function
容器江湖的爱恨情仇
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
PHP Apple internal purchase callback processing
How to play the 2022 Taobao 618 Super Cat Games? What are the strategies for the Super Cat Games
Common configuration commands for Cisco network device security management
2022京东618预售定金怎么退?京东618定金能退吗?
Reverse analysis of Huawei housekeeper software [transfer]
Find the location of a function in PHP
分布式存储探索
PHP download station B video
Get all listening events in the element