venkat_330

paraping based parall port acecss

Aug 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <sys/ioctl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6.  
  7. #include <parapindriver.h>
  8.  
  9. #define CLK LP_PIN01
  10. #define DATA LP_PIN11
  11. #define NCS LP_PIN02
  12.  
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16.   int i, value;
  17.   int device;
  18.   float temp;
  19.  
  20.   /* Get things set up */
  21.   device = open("/dev/ppdrv_device", 0);
  22.  
  23.   if (device < 0) {
  24.     fprintf(stderr, "device open failed, we're outta here\n");
  25.     exit(-1);
  26.   }
  27.  
  28.   ioctl(device, PPDRV_IOC_PINMODE_OUT, CLK | NCS);
  29.   ioctl(device, PPDRV_IOC_PINMODE_IN, DATA);
  30.  
  31.   /* make sure we're in the idle state */
  32.   ioctl(device, PPDRV_IOC_PINSET, NCS);
  33.   ioctl(device, PPDRV_IOC_PINCLEAR, CLK);
  34.  
  35.   /* start a conversion by dropping NCS */
  36.   ioctl(device, PPDRV_IOC_PINCLEAR, NCS);
  37.  
  38.   /* wait for data to go high, signalling the end of conversion */
  39.   while (!ioctl(device, PPDRV_IOC_PINGET, DATA))
  40.     /* null */;
  41.  
  42.   /* clock out 12 bits of data */
  43.   value = 0;
  44.   for (i=0; i<12; i++) {
  45.     value <<= 1;
  46.     ioctl(device, PPDRV_IOC_PINSET, CLK);
  47.     ioctl(device, PPDRV_IOC_PINCLEAR, CLK);
  48.     value |= (ioctl(device, PPDRV_IOC_PINGET, DATA) ? 1 : 0);
  49.   }
  50.  
  51.    /* go back to idle */
  52.   ioctl(device, PPDRV_IOC_PINCLEAR, CLK);
  53.   ioctl(device, PPDRV_IOC_PINSET, NCS);
  54.  
  55.   /* print out the values */
  56.   temp = ((float)value / (float)0x0FFF) * 1250;
  57.   printf("value(hex)=%x;  degC=%.0f;  degF=%.0f\n", value, temp, (temp*(9.0/5.0))+32);
  58.  
  59.  
  60.   /* close the device */
  61.   close(device);
  62.  
  63.   return 0;
  64. }
Add Comment
Please, Sign In to add comment