Chinaunix首页 | 论坛 | 博客
  • 博客访问: 139157
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 876
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-09 10:56
文章分类

全部博文(20)

文章存档

2013年(20)

我的朋友

分类: LINUX

2013-04-18 12:46:18

     本文主要讲解如何测试已写好的驱动。

测试思路是通过采用不同的位选和段选来实现对不同的数码管显示不同的数值。测试程序如下所示。

// 头文件

#include

#include

#include

#include

#include

#include

#include

// 驱动设备号,用于打开时使用

#define DEVICE_NAME "/dev/s3c2440_seg"

#define ALL_LIGHT 7

int main()

{

       int fd, i, j;

       int judge;

       fd = open(DEVICE_NAME, O_RDWR); // 打开驱动设备,注意驱动程序中并没有编写对应的open

                                     // 函数,这里系统采用系统自带的默认open函数,本人做

// 测试的时候没有出现问题

       if(fd < 0)

       {

              perror("open failed.");

              exit(1);

       } 

       while (1)

       {

              printf("Input number 1 to start or Input number 0 to exit!!\n");

              scanf("%d", &judege);     // 首先输入一个数字,输入1进行测试,0退出测试

              if (0 == judge)

              {

                     printf("the program is exiting!!\n");

                     break;

              }

       // 依次从第一个数码管显示0,第二个数码管显示1…

              for(i = 6, j = 0; i > 0;i--)

              {

                     ioctl(fd, i, j++);

                     sleep(1);

              }

              sleep(1);

       // 所有数码管都亮 显示的数值从0F

              for(i = 0; i < 0x10; i++)

              {

                     ioctl(fd, ALL_LIGHT, i);

                     sleep(1);

              }

             

       }

       close(fd);

       return 0;

}

阅读(2263) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~