COM_INT.zip

  • PUDN用户
    了解作者
  • DOS
    开发工具
  • 10KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2008-06-21 23:39
    上传日期
串口程序及原代码与大家共享,谢谢各位网友
COM_INT.zip
  • COM_INT
  • INT3.ASM
    9.8KB
  • COMINT.PRJ
    29B
  • INT4.ASM
    9.8KB
  • COMINT.C
    11.4KB
  • COMINT.DOC
    5.6KB
  • www.pudn.com.txt
    218B
内容介绍
/***************************************************************************** Communication interrupt test program. Created on : September 5th, 1987 By : Dale Loftis GENIE Mail : D.LOFTIS *****************************************************************************/ #include <stdio.h> #include <dos.h> /***************************************************************************** PROGRAM GLOBAL VARIABLES *****************************************************************************/ #if __TURBOC__ /* FOR TURBO C only ! */ #define outp(portid,v) outportb(portid,v) #endif #define BAUD110 0x00 /* available BAUD rates in IBM PC/?? */ #define BAUD150 0x20 #define BAUD300 0x40 #define BAUD600 0x60 #define BAUD1200 0x80 #define BAUD2400 0xA0 #define BAUD4800 0xC0 #define BAUD9600 0xE0 #define NOPARITY 0x00 /* available PARITY options */ #define ODDPARITY 0x08 #define EVENPARITY 0x18 #define STOPBIT1 0x00 /* available STOP BIT options */ #define STOPBIT2 0x04 #define BITS7 0x02 /* available WORD LENGTH options */ #define BITS8 0x03 #define MAXBUF 2048 /* input and output queue size */ /* If you change this be sure to */ /* change INT?.ASM's also */ unsigned char com1_output_queue[MAXBUF];/* COM 1 main Transmit buffer */ unsigned int com1_out_queue_out; /* removal pointer from output_queue */ unsigned int com1_out_queue_ptr; /* insertion pointer to output_queue */ unsigned char com1_input_queue[MAXBUF]; /* COM 1 main Receive buffer */ unsigned int com1_in_queue_out; /* removal pointer from input_queue */ unsigned int com1_in_queue_ptr; /* insertion pointer to input_queue */ unsigned char com2_output_queue[MAXBUF];/* COM 2 main Transmit buffer */ unsigned int com2_out_queue_out; /* removal pointer from output_queue */ unsigned int com2_out_queue_ptr; /* insertion pointer to output_queue */ unsigned char com2_input_queue[MAXBUF]; /* COM 2 main Receive buffer */ unsigned int com2_in_queue_out; /* removal pointer from input_queue */ unsigned int com2_in_queue_ptr; /* insertion pointer to input_queue */ unsigned int com1_rs232_error; /* current COM 1 error code */ unsigned int com2_rs232_error; /* current COM 2 error code */ unsigned int com1_port_status; /* current COM 1 pin status */ unsigned int com2_port_status; /* current COM 2 pin status */ unsigned int com1_interrupt_status; /* current COM 1 interrupt status */ unsigned int com2_interrupt_status; /* current COM 2 interrupt status */ /*****************************************************************************/ main() { while(kbhit()) /* empty keyboard buffer */ getche(); /* throw away the keys without echoing */ com1_set_interrupt(BAUD1200 | /* initialize com1 port and interrupt */ NOPARITY | STOPBIT1 | BITS8); com2_set_interrupt(BAUD1200 | /* initialize com2 port and interrupt */ NOPARITY | STOPBIT1 | BITS8); com1_output_queue_insert("This is how to send out COM 1"); com2_output_queue_insert("This is how to send out COM 2"); scr_clr(); /* clear screen */ while(!kbhit()) /* go until a key is hit */ { queue_delete(1); /* check for incoming COM 1 characters */ queue_delete(2); /* check for incoming COM 2 characters */ show_com_status(); /* show current com1 and com2 status */ } com1_restore_interrupt(); /* replace interrupt vectors before */ com2_restore_interrupt(); /* leaving otherwise its crash city */ } /***************************************************************************** This function displays the status of the buffer pointers, pin status and interrupt status. This is primarily for troubleshooting problems with the interrupts and it slows things down to much for continual usage. *****************************************************************************/ show_com_status() { int row,col,temp; temp = read_cursor_position(); /* find where cursor currently sits */ row = temp >> 8; /* row is high byte */ col = temp & 0xff; /* column is low byte */ scr_rowcol(24,0); /* on the bottom line */ printf( " %04d - %04d %04d - %04d %02xh %02xh %04d - %04d %04d - %04d %02xh %02xh ", com1_in_queue_ptr,com1_in_queue_out, com1_out_queue_ptr,com1_out_queue_out, com1_interrupt_status,com1_port_status, com2_in_queue_ptr,com2_in_queue_out, com2_out_queue_ptr,com2_out_queue_out, com2_interrupt_status,com2_port_status ); if(row != 24) scr_rowcol(row,col); /* put cursor back where it was */ else { scroll(1,1,80,24,1); /* scroll screen up */ scr_rowcol(23,0); /* and start new line */ } } /***************************************************************************** This function looks at the COM ? input and output queue pointers and displays the characters if they are not equal. *****************************************************************************/ queue_delete(port) int port; { int row,temp; switch(port) { case 1: /* COM 1 reception queue check */ while(com1_in_queue_ptr != com1_in_queue_out) /* test for presence of char */ { if(com1_in_queue_out == MAXBUF+1)/* are you at the buffers end? */ com1_in_queue_out = 0; /* YES! then reset to beginning */ if(com1_input_queue[com1_in_queue_out] < 0x20) printf("%x",com1_input_queue[com1_in_queue_out++]); else printf("%c",com1_input_queue[com1_in_queue_out++]); if(com1_rs232_error & 0x1e) /* mask off non-error conditions */ { temp = read_cursor_position(); /* find where cursor currently sits */ row = temp >> 8; /* row is high byte */ if(row == 24) { scroll(1,1,80,24,1); /* scroll screen up */ scr_rowcol(23,0); /* and start new line */ } if(com1_rs232_error & 0x10) printf("Break Detect"); if(com1_rs232_error &0x08) printf("Framing Error"); if(com1_rs232_error & 0x04) printf("Parity Error"); if(com1_rs232_error & 0x02) printf("Overrun Error"); com1_rs232_error = 0; /* reset to no errors */ } } break; case 2: /* COM 2 reception queue check */ while(com2_in_queue_ptr != com2_in_queue_out) /* test for presence of char */ { if(com2_in_queue_out == MAXBUF+1)/* are you at the buffers end? */ com2_in_queue_out = 0; /* YES! then reset to beginning */ if(com2_input_queue[com2_in_queue_out] < 0x20) printf("%x",com2_input_queue[com2_in_queue_out++]); else printf("%c",com2_input_queue[com2_in_queue_out++]); if(com2_rs232_error & 0x1e) /* mask off non-error conditions */ { temp = read_cursor_position(); /* find where cursor currently sits */ row = temp >> 8; /* row is high byte */ if(row == 24) { scroll(1,1,80,24,1); /* scroll screen up */ scr_rowcol(23,0); /* and start new line */ } if(com2_rs232_error & 0x10) printf("Break Detect"); if(com2_rs232_error &0x08) printf("Framing Error"); if(com2_rs232_error & 0x04) printf("Parity Error"); if(com2_rs232_error & 0x02) printf("Overrun Error"); com2_rs232_error = 0; /* reset to no errors */ } } break; } } /**************************************************************************** This function places characters into the COM 1 output queue. Call with: com1_output_queue_insert("Send this out COM 1"); Characters will begin sending as soon as the interrupts are enabled. *****************************************************************************/ com1_output_queue_insert(text) char *text; { while(*text) /* go until end of string */ { while( (com1_out_queue_ptr + 1) % MAXBUF == com1_out_queue_out % MAXBUF) { outp(0x
评论
    相关推荐