Advertisement
Guest User

Untitled

a guest
May 24th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5.  
  6. void _stdcall Out32(short PortAddress, short data);
  7.  
  8.  
  9. typedef short (_stdcall *inpfuncPtr)(short portaddr);
  10. typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
  11.  
  12. #define PPORT_BASE 0x378
  13.  
  14.  
  15. void test_read8(void);
  16. void test_write(void);
  17. void test_write_datum(short datum);
  18.  
  19.  
  20.  
  21. inpfuncPtr inp32fp;
  22. oupfuncPtr oup32fp;
  23.  
  24.  
  25. short Inp32 (short portaddr)
  26. {
  27. return (inp32fp)(portaddr);
  28. }
  29.  
  30. void Out32 (short portaddr, short datum)
  31. {
  32. (oup32fp)(portaddr,datum);
  33. }
  34.  
  35.  
  36. int main(void)
  37. {
  38. HINSTANCE hLib;
  39.  
  40. short x;
  41. int i;
  42.  
  43.  
  44. hLib = LoadLibrary("inpout32.dll");
  45.  
  46. if (hLib == NULL) {
  47. fprintf(stderr,"LoadLibrary Failed.\n");
  48. return -1;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
  55.  
  56. if (oup32fp == NULL) {
  57. fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
  58. return -1;
  59. }
  60.  
  61.  
  62. test_write();
  63.  
  64.  
  65.  
  66.  
  67. FreeLibrary(hLib);
  68. return 0;
  69. }
  70.  
  71.  
  72. void test_read8(void) {
  73.  
  74. short x;
  75. int i;
  76.  
  77.  
  78. for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {
  79.  
  80. x = Inp32(i);
  81.  
  82. printf("Port read (%04X)= %04X\n",i,x);
  83. }
  84.  
  85. }
  86.  
  87.  
  88. void test_write(void) {
  89. short x;
  90. int i;
  91.  
  92.  
  93. i=PPORT_BASE;
  94.  
  95. x=0x00;
  96. Out32(i,x);
  97.  
  98. printf("Se apagan todos los leds");
  99.  
  100. getch();
  101. x=0xFF;
  102. Out32(i,x);
  103. printf("Se prenden todos los leds durante 5 segundos");
  104. Sleep(5000);
  105.  
  106. x=0x00;
  107. Out32(i,x);
  108. printf("Se apagan todos los leds");
  109.  
  110. printf("\n \n Fin de ejecucion... \n \n");
  111. getch();
  112.  
  113. }
  114.  
  115.  
  116. void test_write_datum(short datum) {
  117. short x;
  118. int i;
  119.  
  120. i=PPORT_BASE;
  121. x = datum;
  122.  
  123. Out32(i,x);
  124.  
  125. printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement