Advertisement
Guest User

Untitled

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