Facebook
From 326, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 150
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. #define DATA_PORT 0x378 /* parallel port base address */
  6. #define STATUS_PORT DATA_PORT + 1
  7. #define CONTROL_PORT DATA_PORT + 2
  8.  
  9. unsigned char status, data;
  10.  
  11. void main()
  12. {
  13.     if (ioperm(DATA_PORT, 1, 1))
  14.     {
  15.         fprintf(stderr, "Access denied to %xn", DATA_PORT), exit(1);
  16.     }
  17.  
  18.     while (1)
  19.     {
  20.         for (int seg = 0; seg < 8; seg++)
  21.         {
  22.             data = 1 << seg;
  23.             outb(~data, DATA_PORT); // turn on the segment
  24.             // here we use inversion because the common anode 7-segment display is used
  25.             sleep(1);
  26.         }
  27.     }
  28.  
  29.     ioperm(DATA_PORT, 1, 0); // release the port
  30. }

Replies to Code rss

Title Name Language When
Re: Codesadsad dabuas text 1 Month ago.