集团高端网站,做外贸在哪个网站,网站是如何盈利,做个人网站用什么程序文章目录 1 实验任务2 系统框图3 软件设计 1 实验任务
本实验任务是通过CPU私有定时器来计算按键按下的时间长短。
2 系统框图
参见7.1。
3 软件设计
注意事项#xff1a;
定时器是递减计数的#xff0c;需要考虑StartCount#xff1c;EndCount的情况。
/***********… 文章目录 1 实验任务2 系统框图3 软件设计 1 实验任务
本实验任务是通过CPU私有定时器来计算按键按下的时间长短。
2 系统框图
参见7.1。
3 软件设计
注意事项
定时器是递减计数的需要考虑StartCountEndCount的情况。
/***************************** Include Files ********************************/
#include stdio.h
#include xparameters.h
#include xgpiops.h
#include xscutimer.h
#include xstatus.h
/************************** Constant Definitions ****************************/
#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
#define TIMER_DEVICE_ID XPAR_XSCUTIMER_0_DEVICE_ID#define PS_KEY0_GPIO_PIN 50#define TIMER_LOAD_VALUE 0xFFFFFFFF#define TIMER_CLK_FREQ XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2
/**************************** Type Definitions ******************************//***************** Macros (Inline Functions) Definitions ********************//************************** Function Prototypes *****************************/
int GpioInit(XGpioPs* GpioInstPtr);
int TimerInit(XScuTimer* TimerInstPtr);
/************************** Variable Definitions ****************************/
XGpioPs GpioInst;
XScuTimer TimerInst;u32 StartCount 0;
u32 EndCount 0;
/****************************************************************************/int GpioInit(XGpioPs* GpioInstPtr)
{//int Status;XGpioPs_Config* GpioPsConfigPtr;//GpioPsConfigPtr XGpioPs_LookupConfig(GPIO_DEVICE_ID);Status XGpioPs_CfgInitialize(GpioInstPtr, GpioPsConfigPtr, GpioPsConfigPtr-BaseAddr);if (Status ! XST_SUCCESS) {return XST_FAILURE;}// 设置输入XGpioPs_SetDirectionPin(GpioInstPtr, PS_KEY0_GPIO_PIN, 0);//return XST_SUCCESS;
}int TimerInit(XScuTimer* TimerInstPtr)
{//int Status;XScuTimer_Config* TimerConfigPtr;//TimerConfigPtr XScuTimer_LookupConfig(TIMER_DEVICE_ID);Status XScuTimer_CfgInitialize(TimerInstPtr, TimerConfigPtr, TimerConfigPtr-BaseAddr);if (Status ! XST_SUCCESS) {return XST_FAILURE;}// 自动加载XScuTimer_EnableAutoReload(TimerInstPtr);// 加载初值XScuTimer_LoadTimer(TimerInstPtr, TIMER_LOAD_VALUE);//return XST_SUCCESS;
}int main()
{//int Status;u32 KeyValue;u32 CountDiff;u32 TimerClkFreq TIMER_CLK_FREQ;float PressedTime;//Status GpioInit(GpioInst);if (Status XST_FAILURE) {printf(GPIO Init Failed.\n);}//Status TimerInit(TimerInst);if (Status XST_FAILURE) {printf(Timer Init Failed.\n);}// 启动定时器XScuTimer_Start(TimerInst);//printf(Press the key to start timing...\n);//while(1){// 等待按键按下while (1) {KeyValue XGpioPs_ReadPin(GpioInst, PS_KEY0_GPIO_PIN);if (KeyValue 0) { // 按键按下为低电平StartCount XScuTimer_GetCounterValue(TimerInst);printf(Key pressed, timing started.\n);break;}}// 等待按键释放while (1) {KeyValue XGpioPs_ReadPin(GpioInst, PS_KEY0_GPIO_PIN);if (KeyValue 1) { // 按键释放为高电平EndCount XScuTimer_GetCounterValue(TimerInst);printf(Key released, timing stopped.\n);break;}}// 计算差值if (EndCount StartCount) {printf(EndCount StartCount.\n);CountDiff (0xFFFFFFFF - EndCount) StartCount 1; // 注意定时器会溢出}else {printf(EndCount StartCount.\n);CountDiff StartCount - EndCount; // 注意定时器是递减的}//printf(Key pressed for %lu clock cycles.\n, CountDiff);// 转换为时间PressedTime (float)CountDiff / TimerClkFreq;printf(Key pressed for %.3f seconds.\n, PressedTime);}//return 0;
}
文章转载自: http://www.morning.fmry.cn.gov.cn.fmry.cn http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn http://www.morning.msbpb.cn.gov.cn.msbpb.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.mehrim.com.gov.cn.mehrim.com http://www.morning.rjrnx.cn.gov.cn.rjrnx.cn http://www.morning.grbp.cn.gov.cn.grbp.cn http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.dhbyj.cn.gov.cn.dhbyj.cn http://www.morning.rdlfk.cn.gov.cn.rdlfk.cn http://www.morning.kdtdh.cn.gov.cn.kdtdh.cn http://www.morning.lpsjs.com.gov.cn.lpsjs.com http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.qwrb.cn.gov.cn.qwrb.cn http://www.morning.ttaes.cn.gov.cn.ttaes.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.nqpy.cn.gov.cn.nqpy.cn http://www.morning.ckwxs.cn.gov.cn.ckwxs.cn http://www.morning.cbmqq.cn.gov.cn.cbmqq.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.kdnrp.cn.gov.cn.kdnrp.cn http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn http://www.morning.fppzc.cn.gov.cn.fppzc.cn http://www.morning.plznfnh.cn.gov.cn.plznfnh.cn http://www.morning.rltsx.cn.gov.cn.rltsx.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.pwzzk.cn.gov.cn.pwzzk.cn http://www.morning.nkwgy.cn.gov.cn.nkwgy.cn http://www.morning.ktrdc.cn.gov.cn.ktrdc.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.zcsyz.cn.gov.cn.zcsyz.cn http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn http://www.morning.lbfgq.cn.gov.cn.lbfgq.cn http://www.morning.kzdgz.cn.gov.cn.kzdgz.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.tqqfj.cn.gov.cn.tqqfj.cn http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn http://www.morning.kfclh.cn.gov.cn.kfclh.cn http://www.morning.bwznl.cn.gov.cn.bwznl.cn http://www.morning.ksbmx.cn.gov.cn.ksbmx.cn http://www.morning.ldhbs.cn.gov.cn.ldhbs.cn http://www.morning.mrfgy.cn.gov.cn.mrfgy.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.ypdmr.cn.gov.cn.ypdmr.cn http://www.morning.lqznq.cn.gov.cn.lqznq.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.kqblk.cn.gov.cn.kqblk.cn http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.nfbkz.cn.gov.cn.nfbkz.cn http://www.morning.lqws.cn.gov.cn.lqws.cn http://www.morning.pcxgj.cn.gov.cn.pcxgj.cn http://www.morning.hsjfs.cn.gov.cn.hsjfs.cn http://www.morning.mkrjf.cn.gov.cn.mkrjf.cn http://www.morning.fywqr.cn.gov.cn.fywqr.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn http://www.morning.pmysp.cn.gov.cn.pmysp.cn http://www.morning.lkpzx.cn.gov.cn.lkpzx.cn http://www.morning.kmcby.cn.gov.cn.kmcby.cn http://www.morning.wkkqw.cn.gov.cn.wkkqw.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.bysey.com.gov.cn.bysey.com http://www.morning.zmwzg.cn.gov.cn.zmwzg.cn http://www.morning.dwrbn.cn.gov.cn.dwrbn.cn http://www.morning.jfjbl.cn.gov.cn.jfjbl.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.jrdbq.cn.gov.cn.jrdbq.cn http://www.morning.mnqz.cn.gov.cn.mnqz.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.frtt.cn.gov.cn.frtt.cn http://www.morning.wbysj.cn.gov.cn.wbysj.cn http://www.morning.qzdxy.cn.gov.cn.qzdxy.cn