test.c

来自「该程序是在S3C2410基础上开发的Linux流水灯驱动程序」· C语言 代码 · 共 31 行

C
31
字号
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
static int fd = -1;
int main(void)
{
  int i,out;
  out = 0xe0;
  fd = open("/dev/IO/0",O_RDWR);
  if(fd<0)
    {
	  printf("failed to open the device \n");
	}
  else
  printf("successed to open the device \n");
  while(1)
    {
	  ioctl(fd , out);
	  for(i=0;i<5000000;i++);
	  out=(out<<1) & 0xf0;  //注意,这里一定要加“& 0xf0”这一项,因为0xe0<<1后就变成了0x1c0,为了把那个1变成0而只获取有用的四位,所以加“& 0xf0”这一项
	 // printf("out=%x \n",out);
       if(out!=0xe0) out|=0x10;
	 // printf("out=%x \n",out);
	  
    }
   close(fd);
   printf("end of test \n");
   return 0;	
}

⌨️ 快捷键说明

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