测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "stdio.h"
#include "sys/types.h"
#include "sys/ioctl.h"
#include "stdlib.h"
#include "termios.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "sys/time.h"
#define uchar unsigned char
#define uint unsigned int
//uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//uchar code LED_W[8] = {0,1,2,3,4,5,6,7};
int fd;
void choose_num(int seg);
void Delay(uint i);
void choose_site(int site);
#define test 1
int main()
{
int on = 1;
int led;
if((fd = open("/dev/wyz_leds",0)) < 0)
{
perror("open device false,the problem is what");
exit(1);
}
printf("it is ok\n");
#ifdef test
while(1)
{
choose_num(0); //1
choose_site(0); //
Delay(3);
choose_num(1);
choose_site(1);
Delay(3);
choose_num(2); //1
choose_site(2); //
Delay(3);/*
choose_num(3);
choose_site(3);
Delay(3);
choose_num(4); //1
choose_site(4); //
Delay(3);
choose_num(5);
choose_site(5);
Delay(3);
choose_num(6); //1
choose_site(6); //
Delay(3);
choose_num(7);
choose_site(7);
Delay(3);*/
}
#else
while(1)
{
for(led=0;led<4;led++)
{
ioctl(fd, on, led);
usleep(5000);
printf("tell me led is %d\n",led);
}
on=!on;
//sleep(5000);
printf("it will light\n");
}
#endif
printf("if jump out,is ok?\n");
close(fd);
return 0;
}
void choose_num(int seg)
{
//int on=1;
//int led;
int i=0;
switch(seg)
{
case 0:{ //0x3f
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 1 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 0 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is zero\n");
}while(i--);
break;
}
case 1:{ //0x06
//i=1;
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 1 , 1 );
ioctl(fd , 1 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 1 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 1 , 7 );
do{
printf("now is one\n");
printf("%d\n",i);
//sleep(1);
}while(i--);
break;
}
case 2:{ //0x5b
//for(led=0;led<8;led++)
//i=1;
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 1 , 2 );
ioctl(fd , 0 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 1 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is two\n");
printf("%d\n",i);
sleep(1);
}while(i--);
break;
}
case 3:{ //0x4f
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 1 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is three\n");
}while(i--);
break;
}
case 4:{ //0x66
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 1 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 1 , 7 );
do{
printf("now is four\n");
}while(i--);
break;
}
case 5:{ //0x6d
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 1 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is five\n");
}while(i--);
break;
}
case 6:{ //0x7d
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 0 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 1 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is six\n");
}while(i--);
break;
}
case 7:{ //0x07
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 1 , 1 );
ioctl(fd , 1 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 1 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is server\n");
}while(i--);
break;
}
case 8:{ //0x7f
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 0 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is eight\n");
}while(i--);
break;
}
case 9:{ //0x6f
//for(led=0;led<8;led++)
ioctl(fd , 1 , 0 );
ioctl(fd , 0 , 1 );
ioctl(fd , 0 , 2 );
ioctl(fd , 1 , 3 );
ioctl(fd , 0 , 4 );
ioctl(fd , 0 , 5 );
ioctl(fd , 0 , 6);
ioctl(fd , 0 , 7 );
do{
printf("now is nine\n");
}while(i--);
break;
}
default:
break;
}
}
void Delay(uint i)
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
void choose_site(int site)
{
int i=0;
switch(site)
{
case 0:{
ioctl(fd , 0 , 8 );
ioctl(fd , 0 , 9);
ioctl(fd , 0 , 10);
do{
printf("now ths first is choose\n");
}while(i--);
break;
}
case 1:{
ioctl(fd , 0 , 8 );
ioctl(fd , 0 , 9);
ioctl(fd , 1 , 10);
do{
printf("now ths second is choose\n");
}while(i--);
break;
}
case 2:{
ioctl(fd , 0 , 8 );
ioctl(fd , 1 , 9);
ioctl(fd , 0 , 10);
do{
printf("now ths third is choose\n");
printf("%d\n",i);
}while(i--);
break;
}
case 3:{
ioctl(fd , 0 , 8 );
ioctl(fd , 1 , 9);
ioctl(fd , 1 , 10);
do{
printf("now ths fourth is choose\n");
}while(i--);
break;
}
case 4:{
ioctl(fd , 1 , 8 );
ioctl(fd , 0 , 9);
ioctl(fd , 0 , 10);
do{
printf("now ths fifth is choose\n");
}while(i--);
break;
}
case 5:{
ioctl(fd , 1 , 8 );
ioctl(fd , 0 , 9);
ioctl(fd , 1 , 10);
do{
printf("now ths sixth is choose\n");
}while(i--);
break;
}
case 6:{
// i=1;
ioctl(fd , 1 , 8 );
ioctl(fd , 1 , 9);
ioctl(fd , 0 , 10);
do{
printf("now ths seventh is choose\n");
printf("%d\n",i);
}while(i--);
break;
}
case 7:{
//i=1;
ioctl(fd , 1 , 8 );
ioctl(fd , 1 , 9);
ioctl(fd , 1 , 10);
do{
printf("now ths eighth is choose\n");
printf("%d\n",i);
sleep(1);
}while(i--);
break;
}
defult:
break;
}
}