⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 44b0/linux环境基本实验源码,包括helloworld,线程,串口,AD,DA,CAN总线,LED,电机,GPS,GPRS,键盘驱动等
💻 C
字号:
/************************************************\*	by threewater<threewater@up-tech.com>	**		2003.12.18			**						*\***********************************************/#include <stdio.h>#include <fcntl.h>#include <string.h>//#include <sys/types.h>//#include <sys/ipc.h>#include <sys/ioctl.h>#include "hardware.h"#include "exio.h"#include "s3c44b0-spi.h"#define MAX504_CS			0x2		//EXIO1#define MAX504_CLR			0x1		//EXIO0#define SIOLSB				0x40#define MAX504_CLEAR()			do{CLREXIOBIT(MAX504_CLR);	Delay(1); SETEXIOBIT(MAX504_CLR);}while(0)#define Max504_FULL			4.096f#define SPI_DEV		"/dev/spi/0"static int spi_fd = -1;void Delay(int t){	int i;	for(;t>0;t--)		for(i=0;i<400;i++);}void Max504_SetDA(int value){	value<<=2;	MAX504_CLEAR();	Delay(1);		ioctl(spi_fd, SPI_IOCTRL_WFORMAX504, value);}int main(int argc, char **argv){	float v;	int value;	if(argc!=2){		printf("Error parameter\n");		return 1;	}	sscanf(argv[1], "%f",&v);		if(v<0 || v>Max504_FULL){		printf("DA out must between: 0 to %f\n", Max504_FULL);		return 1;	}		init_exio();	if((spi_fd=open(SPI_DEV, O_NONBLOCK))<0){		printf("Error opening %s spi device\n", SPI_DEV);		return 1;	}		value=(int)((v*1024.0f)/Max504_FULL);	Max504_SetDA(value);		close(spi_fd);                                                         	printf("Current Voltage is %f V\n", v);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -