´ÙÀ½ ÀÌÀü Â÷·Ê

9. ¼ÒÇÁÆ®¿þ¾î ¿¹Á¦

¿©±â¿¡´Â I/O Æ÷Æ®¸¦ ¿¢¼¼½ºÇÒ¼ö ÀÖ´Â °£´ÜÇÑ ¿¹Á¦ Äڵ尡 ÀÖ´Ù.


/*
 * example.c: °£´ÜÇÑ Æ÷Æ® ÀÔÃâ·Â ¿¹Á¦
 *
 * ÀÌ ÄÚµå´Â Ưº°È÷ ¾µ¸¸ÇÑ °Ç ¾ø°í , Æ÷Æ®¿¡ ¾²°í, Àá½Ã ¸ØÃá ´ÙÀ½, 
 * Æ÷Æ®¸¦ Àд´Ù. `gcc -O2 -o example example.c'·Î ÄÄÆÄÀÏÇÑ´Ù.
 */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
#define BASEPORT 0x378 /* lp1 */
int main()
{
  /* Get access to the ports */
  if (ioperm(BASEPORT,3,1)) {perror("ioperm");exit(1);}
  
  /* Set the data signals (D0-7) of the port to all low (0) */
  outb(0,BASEPORT);
  
  /* Sleep for a while (100 ms) */
  usleep(100000);
  
  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n",inb(BASEPORT+1));
  /* We don't need the ports anymore */
  if (ioperm(BASEPORT,3,0)) {perror("ioperm");exit(1);}
  exit(0);
}
/* end of example.c */


´ÙÀ½ ÀÌÀü Â÷·Ê