Thursday, February 4, 2016

Write a programe to print some number on 7 segment taken from user.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define  NODE_EXP                         "/dev/7seg_led"

#define  SEG_7_LED_ON                 1   /* Device name */
#define  SEG_7_LED_WRITE           2
#define  SEG_7_LED_CLEAR           3
#define  SEG_7_LED_OFF                4


/* Application : To test the functionaity of LCD Driver */

int main ()
{
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */
    int num;  /*  input value */
    /* open as blocking mode */
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

                if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )      /* Ioctl */
        {
                    printf("%d---> Error in switching OFF the LED \r\n",res);
                    close(exp_dev);
                    return 1;
                }
/* *********************INPUT TAKEN FROM USER*********************** */
        printf("Enter input from user ");
                scanf("%d",&num);
/* *********************INPUT TAKEN FROM USER*********************** */
           if (res=ioctl(exp_dev,SEG_7_LED_WRITE, num) < 0 )
         {
            printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
            close(exp_dev);
            return 1;
          }
        printf ("Press any key to exit from the program\n");
        getchar();
                if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
               {
                    printf("%d---> Error in Clearing the LED \r\n",res);
                    close(exp_dev);
                    return 1;
                }
                if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
             {
                    printf("Error in switching OFF the LED \r\n");
                    close(exp_dev);
                    return 1;
                }

    close(exp_dev);
    exit(1);
}

No comments:

Post a Comment