资源描述:
《windows 中断程序设计 》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Windows中断程序设计摘要该文探讨ing//lastmodifiedonJune25,1996#include〈windows.h〉#include〈dos.h〉voidinterruptfarDataReceive();voidinterruptfar(*old-vector)();unsignedchardata-r[1024],data-s[1024];intinflag=0;unsignedints8259;intInit1(){//串口1初使化s8259=inportb(0x21);//读入8259当前状态并保存outpor
2、tb(0x21,s82590xe8);//初始化8259,允许0x0c号中断outportb(0x3fb,0x83);outportb(0x3f8,0x0c);outportb(0x3f9,0x00);outportb(0x3fb,0x03);outportb(0x3fc,0x08);//允许中断信号送到8259A,以便能中断outportb(0x3f9,0x01);//0x01,中断允许return1;}voidinterruptfarDataReceive(){//中断接收子程序staticinti=0;//静态局部变量charrec
3、har=0;//每中断一次,i自动加1rechar=inportb(0x3f8);//从数据口读出发送过来的数据if(inflag==0){if(rechar!=si==0)//帧起始{i=0;gotoll;}data-r[i++]=rechar;//存入data-r[](通信缓冲区)if(rechar==e)//帧结束{inflag=1;i=0;}}ll:outportb(0x20,0x20);//回送中断结束标志}//调用DPMI//保存旧的0CH号保护模式中断向量//设置新的保护模式中断服务例程voidInit(void){
4、asm{climovax,204hmovbl,0chint31hsti}old-vector=MK-FP(-CX,-DX);//保存asm{cli//设置新的0x0c中断服务例程movax,205hmovbl,0chmovcx,segdatareceivemovdx,offsetdatareceiveint31hsti}Init1();}//恢复8259状态//恢复0CH保护模式向量voidRestorem(void){outportb(0x21,s8259);asm{climovax,205hmovbl,0chmovcx,segold-
5、vectormovdx,offsetold-vectorint31hsti}}在窗口第一次被创建时会传送它-CREATE消息,这时调用Init()即可。在主窗口关闭时,即主窗口中收到-DESTROY消息时,调用Restorem()恢复原来的状态。这样在对串口初始化,设置中断服务例程后,通信事件发生时,会立即跳入中断子程序中执行,越过系统的消息队列,达到实时处理通信事件的目的。而数据处理模块可通过全局标志flag访问全局的数据通信缓冲区获取实时数据。这种实现方式与基于消息机制的WindoI),系统也运行良好。