📄 spi_write_register.c
字号:
/*******************************************************************************
* Serial Peripheral Interface (4-wire SPI) register write. *
* Syntax: Status = Spi_Write_Register(Port, Address, Value) *
* *
* Input Parameters: *
* ================ *
* *
* Port --------> Parallel port base address decimal (positive integer). *
* Address -----> Register address decimal (positive integer). *
* Value -------> Register value decimal (positive integer). *
* *
* Output Parameters: *
* ================= *
* *
* Status ------> Success status (-1 = error, +1 = success). *
* *
* See also Spi_Read_Register(). *
* *
* Compile: mex -v spi_write_register.c ms_spi.c inpout32.lib *
* Version: 02-02-2005 *
* *
* (C) 2005 Stephan Hengstler, Stanford Wireless Sensor Networks Lab *
*******************************************************************************/
#include <stdio.h>
#include <windows.h>
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
double *result;
int status;
short address, port, value;
/* get the value(s) of the input variable(s) */
port = (short) mxGetScalar(prhs[0]);
address = (short) mxGetScalar(prhs[1]);
value = (short) mxGetScalar(prhs[2]);
/* call the respective subroutine(s) */
status = spi_write_register(port, address, value);
/* set the value(s) of the output variable(s) */
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
result = mxGetPr(plhs[0]);
*result = status;
/* show debug information */
if (nrhs == 4)
{
printf("Debug Information\n");
printf("port = %d\n", port);
printf("address = %d\n", address);
printf("value = %d\n", value);
printf("status = %d\n", status);
}
/* clean exit */
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -