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

📄 master_old.c

📁 s3c2410的很多驱动实验
💻 C
字号:
#include     <stdio.h>      /*标准输入输出定义*/#include     <stdlib.h>     /*标准函数库定义*/#include     <unistd.h>     /*Unix标准函数定义*/#include     <sys/types.h>  /**/#include     <sys/stat.h>   /**/#include     <fcntl.h>      /*文件控制定义*/#include     <asm/termios.h>    /*PPSIX终端控制定义*/#include     <errno.h>      /*错误号定义*/int main(void){	struct termios options;		//串口参数设置结构体		int i;	int fd;	int nread;	char buff_r[512];	char buff_w[512];	int len;		fd = open("/dev/ttyS1", O_RDWR|O_NOCTTY);	//打开串口0	if (fd<0)	{		printf("Can't Open Serial Port!\n");		exit(0);	}			tcgetattr(fd, &options);	//获取串口结构体的属性(当前端口的参数值)		/*设置串口波特率*/	cfsetispeed(&options, B115200);	//修改接收速率	cfsetospeed(&options, B115200);	//修改发送速率			/*设置数据位,停止位,校验位*/	options.c_cflag &= ~CSIZE;	//控制模式,屏蔽字符大小位	options.c_cflag |= CS8;		//设置8位数据位数	options.c_cflag &= ~CSTOPB;	//1位停止位	options.c_cflag &= ~PARENB;	//无奇偶校验位		/*其它设置*/	options.c_cflag |= (CLOCAL|CREAD);		//使能接收,并设置本地状态	options.c_cflag &= ~CRTSCTS;			//无流控制		/*对接收数据的设置*/	options.c_iflag &= ~ICRNL;	//CR不转换为NL	options.c_iflag &= ~INLCR;	//NL不转换为CR		/*对发送数据的设置*/	options.c_oflag &= ~OPOST;  /*选择原始输出法*/	options.c_oflag &= ~OCRNL;	//CR不转换为NL	options.c_oflag &= ~ONLCR;	//NL不转换为CR		/*线控制的设置*/	options.c_lflag &= ~ECHO;		//不回显	options.c_lflag &= ~ECHONL;		//不回显换行	options.c_lflag &= ~ISIG;		//不	options.c_lflag &= ~(ICANON | ECHOE | ECHOK);    /*选择原始输入法*/		/*控制字符的设置*/		options.c_cc[VTIME] = 150; 	// 等待数据的时间:15 seconds   	options.c_cc[VMIN] = 1;		// 将要读字符的最小数目			tcsetattr(fd, TCSANOW, &options);	//为串口设置新的参数	tcflush(fd,TCIOFLUSH); 				//更新参数并立即生效			printf("please enter any data to the ttyS1\n");	printf("Enter key to confirm\n");		for(i=0;i<15;i++)		buff_w[i] = i+1;	while(1)	{		printf("\n1111\n");		getchar();		tcflush(fd,TCIOFLUSH); 				//		write(fd,buff_w,15);		printf("2222\n");		/*		len = 0;		while((nread = read(fd,buff_r,15))>0)		{			printf("\nLen %d\n",nread);			printf("receive data are:\n");			for(i=len;i<len+nread;i++)			{				buff_w[i] = buff_r[i];				printf(" %d",buff_r[i]);			}			len += nread;			if(len==15) break;		}*/				len = 0; 		while( (nread = read(fd,buff_r,15))>0)		{			printf("\nLen %d\n",nread);			printf("receive data are:\n");			for(i=0;i<nread;i++)				printf(" %d",buff_r[i]);			printf("\n");			len += nread;			printf(" num is %d\n",len);			if(len==15) break;		}	}	close(fd);}

⌨️ 快捷键说明

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