SHARE
TWEET

Untitled

a guest Nov 21st, 2014 6 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<dos.h>
  3. #include<conio.h>
  4. #include<process.h>
  5. #define PORT 0x03F8 /* the address of COM1 */
  6. /* the address offset value relative to COM1 */
  7. #define THR 0x0000
  8. #define RDR 0x0000
  9. #define BRDL 0x0000
  10. #define IER 0x0001
  11. #define BRDH 0x0001
  12. #define LCR 0x0003
  13. #define MCR 0x0004
  14. #define LSR 0x0005
  15. #define MSR 0x0006
  16. unsigned char rdat[60];
  17. /* read 2 data from address 2102H of AC drive with address 1 */
  18. unsigned char tdat[60]={':','0','1','0','3','2','1','0','2',
  19. '0','0','0','2','D','7','\r','\n'};
  20. void main(){
  21. int i;
  22. outportb(PORT+MCR,0x08); /* interrupt enable */
  23. outportb(PORT+IER,0x01); /* interrupt as data in */
  24. outportb(PORT+LCR,(inportb(PORT+LCR) | 0x80));
  25. /* the BRDL/BRDH can be access as LCR.b7==1 */
  26. outportb(PORT+BRDL,12); /* set baudrate=9600,
  27. 12=115200/9600*/
  28. outportb(PORT+BRDH,0x00);
  29. outportb(PORT+LCR,0x06); /* set protocol, <7,N,2>=06H
  30. <7,E,1>=1AH, <7,O,1>=0AH
  31. <8,N,2>=07H, <8,E,1>=1BH
  32. <8,O,1>=0BH */
  33. for(i=0;i<=16;i++){
  34. while(!(inportb(PORT+LSR) & 0x20)); /* wait until THR empty */
  35. outportb(PORT+THR,tdat[i]); /* send data to THR */
  36. }
  37. i=0;
  38. while(!kbhit()){
  39. if(inportb(PORT+LSR) & 0x01){ /* b0==1, read data ready */
  40. rdat[i++]=inportb(PORT+RDR); /* read data form RDR */
  41. } } }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top