dos下串口通信编程.doc





《dos下串口通信编程.doc》由会员分享,可在线阅读,更多相关《dos下串口通信编程.doc(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、中断向量表INT (Hex) IRQ Common Uses08 0 System Timer09 1 Keyboard0A 2 Redirected0B 3 Serial Comms. COM2/COM40C 4 Serial Comms. COM1/COM3 0D 5Reserved/Sound Card 0E 6 Floppy Disk Controller 0F7 Parallel Comms. 70 8 Real Time Clock71 9 Reserved72 10 Reserved73 11 Reserved74 12 PS/2 Mouse75 13Maths Co-Proce
2、ssor76 14 Hard Disk Drive77 15 Reserved 通过编写COM对应的中断服务程序,我们也可以操作串口,涉及到的相关函数有:(1)设置中断向量表/*dos.h*/void _Cdecl setvect (int interruptno, void interrupt (*isr) ();例如,COM3对应的中断号是4,那么对应中断向量表中的地址是0x0C,设置0x0C对应中断程序的函数为:setvect(0x0C, PORT1INT);其中的中断服务程序PORT1INT为:void interrupt PORT1INT()int c;doc = inportb(P
3、ORT1 + 5);if (c &1)bufferbufferin = inportb(PORT1);bufferin+;if (bufferin = 1024)bufferin = 0;while (c &1);outportb(0x20, 0x20);上述中断服务程序检查是否有字符可接收,其后将其通过inportb(PORT1)语句将其从UART中读出并放入输入buffer。持续的检查UART,以便能在一次中断里读取所有可获得的数据。最后的outportb(0x20,0x20);语句告诉可编程中断控制器(Programmable Interrupt Controller,PIC)中断已经完
4、成。(2)读取中断向量表/*dos.h*/void interrupt (* _Cdecl getvect(int interruptno) ();例如:oldport1isr = getvect(INTVECT); 其中的oldport1isr定义为:void interrupt (*oldport1isr)();我们融合setvect()函数、中断服务程序和getvect()函数,给出一个由Craig Peacock编写的完备例程:/* Name : Sample Comms Program - 1024 Byte Buffer - buff1024.c */* Written By :
5、Craig Peacock */#include #include #include #define PORT1 0x3F8 /* Port Address Goes Here */#define INTVECT 0x0C /* Com Ports IRQ here (Must also change PIC setting) */* Defines Serial Ports Base Address */* COM1 0x3F8 */* COM2 0x2F8 */* COM3 0x3E8 */* COM4 0x2E8 */int bufferin = 0;int bufferout = 0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- dos 串口 通信 编程

限制150内