标题:求助高手帮我注释下这个LED测试代码,有doc附件可下载方便注释,先谢谢啦
只看楼主
jizhumizhu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-6
结帖率:100%
已结贴  问题点数:20 回复次数:2 
求助高手帮我注释下这个LED测试代码,有doc附件可下载方便注释,先谢谢啦
led测试代码.rar (4.74 KB)

在pxa270目录下新建文件夹,命名为led_test,在该文件夹下利用gedit编辑器,编写一个Led驱动测试代码led_test.c;
/************************************************
*************************************************/
#include <stdio.h>
#include <fcntl.h>
//#include <linux/kernel.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <pthread.h>
#include <time.h>
#include <stdbool.h>

#define LED_DEV        "/dev/xsb_Led"
bool bstop=false;
int fd;

void display_menu()
{
    printf("       *****Choice Menu*********\n");
    printf("         [0]  Open Device\n");
    printf("         [1]  Left Shift\n");
    printf("         [2]  Right Shift\n");
    printf("         [T]  Stop Shift\n");
    printf("         [C]  Close Device\n");   
    printf("         [x]  Exit Test\n");
    printf("       ***********************\n");
    printf(" Please input your choise: ");   
}

void *Led_Right_Shift(void *data)
{
    unsigned char ledvalue=0x01;
    unsigned char tmp;
    int i=0;
    while(1) {
        for(i=0;i<8;i++){
            if(bstop)     {
                bstop=false;
                return;
            }
            tmp=~ledvalue;
            write(fd,&tmp,1);
            sleep(1);
            if(i<7)
                ledvalue=ledvalue<<1;
            else
                ledvalue=0x01;
        }
    }
}
void *Led_Left_Shift(void *data)
{
        unsigned char ledvalue=0x80;
        unsigned char tmp;
        int i=0;
        while(1)  {
                for(i=0;i<8;i++) {
            if(bstop) {
                bstop=false;
                return;
            }
                        tmp=~ledvalue;
                        write(fd,&tmp,1);
                        sleep(1);
                        if(i<7)
                                ledvalue=ledvalue>>1;
                        else
                                ledvalue=0x80;
                }
        }
}


int main(int argc, char **argv)
{
    fd=-1;
    pthread_t th_shift=0;
    char ch=0x00;
    display_menu();
    void *retval;
    while(1) {
      
            ch=getchar();
            switch(ch)   {
        case '0':
          if(fd>0)
             printf("##Led Device has been open##%d \n",fd);
          else   {
              fd = open(LED_DEV, O_RDWR);
              if(fd < 0)
                     printf("####LED Device open Fail####\n");
              else
                     printf("####LED Device open Success####%d \n",fd);
          }
          display_menu();
          break;
        case '1':
            if(fd) {
                if(th_shift) {
                    bstop=true;
                    pthread_join(th_shift,&retval);
                }
                bstop=false;
                pthread_create(&th_shift,NULL,Led_Right_Shift,NULL);
            }
            else   
                printf("The device is not open!!");
            display_menu();
            break;
                case '2':
            if(fd)     {
                if(th_shift) {
                    bstop=true;
                    pthread_join(th_shift,&retval);
                }
                bstop=false;
                            pthread_create(&th_shift,NULL,Led_Left_Shift,NULL);
            }
            else
                printf("The device is not open!!");
                        display_menu();
                        break;

        case 't':
        case 'T':
            bstop=true;
            display_menu();
            break;
        case 'c':
        case 'C':
            if(fd)
                close(fd);
            display_menu();
            bstop=false;
            break;
        case 'x':
        case 'X':
            exit(1);
        default:
            break;
            }
    }
    return(0);
}


[ 本帖最后由 jizhumizhu 于 2010-12-6 10:34 编辑 ]
搜索更多相关主题的帖子: 新建文件夹 false linux 编辑器 
2010-12-06 10:30
fightingsss
Rank: 6Rank: 6
等 级:侠之大者
帖 子:97
专家分:471
注 册:2010-11-12
得分:14 
这。。。
2010-12-07 08:58
jizhumizhu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-6
得分:0 
没有人能帮帮我吗
2010-12-08 12:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-328052-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.689746 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved