Advertisement
Guest User

Untitled

a guest
May 27th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. /*******************************************************/
  2. /* */
  3. /* Builds with Borland's Command-line C Compiler */
  4. /* (free for public download from Borland.com, at */
  5. /* http://www.borland.com/bcppbuilder/freecompiler ) */
  6. /* */
  7. /* Compile with: */
  8. /* */
  9. /* BCC32 -IC:\BORLAND\BCC55\INCLUDE TEST2.C */
  10. /* */
  11. /* */
  12. /* Be sure to change PPORT_BASE (Port Base address) */
  13. /* accordingly if your LPT port is addressed */
  14. /* elsewhere. */
  15. /* */
  16. /*******************************************************/
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <conio.h>
  21. #include <windows.h>
  22.  
  23.  
  24. /* Definitions in the build of inpout32.dll are: */
  25. /* short _stdcall Inp32(short PortAddress); */
  26. void _stdcall Out32(short PortAddress, short data);
  27.  
  28. /* prototype (function typedef) for DLL function Inp32: */
  29.  
  30. typedef short (_stdcall *inpfuncPtr)(short portaddr);
  31. typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
  32.  
  33. #define PPORT_BASE 0x378
  34.  
  35.  
  36. // Prototypes for Test functions
  37. void test_read8(void);
  38. void test_write(void);
  39. void test_write_datum(short datum);
  40.  
  41.  
  42. /* After successful initialization, these 2 variables
  43. will contain function pointers.
  44. */
  45. inpfuncPtr inp32fp;
  46. oupfuncPtr oup32fp;
  47.  
  48.  
  49. /* Wrapper functions for the function pointers
  50. - call these functions to perform I/O.
  51. */
  52. short Inp32 (short portaddr)
  53. {
  54. return (inp32fp)(portaddr);
  55. }
  56.  
  57. void Out32 (short portaddr, short datum)
  58. {
  59. (oup32fp)(portaddr,datum);
  60. }
  61.  
  62.  
  63. int main(void)
  64. {
  65. HINSTANCE hLib;
  66.  
  67. short x;
  68. int i;
  69.  
  70.  
  71. /* Load the library */
  72. hLib = LoadLibrary("inpout32.dll");
  73.  
  74. if (hLib == NULL) {
  75. fprintf(stderr,"LoadLibrary Failed.\n");
  76. return -1;
  77. }
  78.  
  79.  
  80.  
  81.  
  82. oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
  83.  
  84. if (oup32fp == NULL) {
  85. fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
  86. return -1;
  87. }
  88.  
  89.  
  90. /*******************************************************/
  91. /** IF WE REACHED HERE, INITIALIZED SUCCESSFUL ******/
  92. /*******************************************************/
  93.  
  94. /* now test the functions */
  95.  
  96.  
  97. /***** Read 8 bytes at I/O base address */
  98. // test_read8();
  99.  
  100. // getch();
  101.  
  102. /***** Write 0x75 to data register and verify */
  103. test_write();
  104.  
  105.  
  106.  
  107. /***** One more time, different value */
  108. // test_write_datum(0xAA);
  109.  
  110.  
  111. /* finished - unload library and exit */
  112. FreeLibrary(hLib);
  113. return 0;
  114. }
  115.  
  116. /*
  117. TEST: Read inputs of 8 registers from PORT_BASE address
  118. */
  119. void test_read8(void) {
  120.  
  121. short x;
  122. int i;
  123.  
  124. /* Try to read 0x378..0x37F, LPT1: */
  125.  
  126. for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {
  127.  
  128. x = Inp32(i);
  129.  
  130. printf("Port read (%04X)= %04X\n",i,x);
  131. }
  132.  
  133. }
  134.  
  135. /*
  136. TEST: Write constant 0x77 to PORT_BASE (Data register)
  137. */
  138. void test_write(void) {
  139. short x;
  140. int i;
  141.  
  142. /***** Write the data register */
  143.  
  144. i=PPORT_BASE;
  145.  
  146. x=0x00;
  147. Out32(i,x);
  148.  
  149. x=0xAA;
  150.  
  151. /***** Write the data register */
  152. Out32(i,x);
  153.  
  154. printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
  155.  
  156. /***** And read back to verify
  157. x = Inp32(i);
  158. printf("Port read (%04X)= %04X\n",i,x);*/
  159. printf("\n \n Listo led 1 ... Esperando 5 seg..\n \n");
  160. Sleep(5000);
  161.  
  162. /***** Set all bits high */
  163. x=0xFF;
  164. Out32(i,x);
  165. printf("\n \n Listo led 2 ... Esperando 7 seg..\n \n");
  166. Sleep(7000);
  167. x=0x00;
  168. Out32(i,x);
  169. system("cls");
  170. printf("\n \n Amonos !!!\n \n");
  171. for (int n=1;n<21;n++)
  172. {
  173. x=0x001;
  174. Out32(i,x);
  175. Sleep(500);
  176. x=0x080;
  177. Out32(i,x);
  178. Sleep(500);
  179. }
  180. x=0x000;
  181. Out32(i,x);
  182. printf("\n \n Fin de ejecucion... \n \n");
  183. getch();
  184.  
  185. }
  186.  
  187. /*
  188. TEST: Write data from parameter
  189. */
  190. void test_write_datum(short datum) {
  191. short x;
  192. int i;
  193.  
  194. i=PPORT_BASE;
  195. x = datum;
  196.  
  197. /***** Write the data register */
  198. Out32(i,x);
  199.  
  200. printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
  201.  
  202. /***** And read back to verify *
  203. x = Inp32(i);
  204. printf("Port read (%04X)= %04X\n",i,x);*/
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement