Monday, February 8, 2016

Wap a Programe to print some numbers or message on LCD screen.

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

#define  NODE_EXP                           "/dev/7seg_led"
#define  LCD_ON                                1   /* Device name */
#define  LCD_CLEAR                         2
#define  LCD_SET_HOME                 3
#define  LCD_CURSOR_BLINK         4
#define  LCD_DATA_WRITE              5
#define  LCD_OFF                             6

/* 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 */

    /* 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 )   
              {
                    printf("%d---> Error in switching OFF the LED \r\n",res);
                    getchar();
                    close(exp_dev);
                    return 1;
                }
           if (res=ioctl(exp_dev,SEG_7_LED_WRITE, 0x1234) < 0 )
         {
            printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
            getchar();
            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);
            getchar();
            close(exp_dev);
             return 1;
            }
           if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
          {
            printf("Error in switching OFF the LED \r\n");
            getchar();
            close(exp_dev);
            return 1;
             }
          close(exp_dev);
         exit(1);
  }

No comments:

Post a Comment