单片机开发之cc2530的远程定位装置---------中断调用总结

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_39928074/article/details/81623789

对于第一次接触单片机的小白来说,明明自己没有看见main()函数中有调用函数,为什么在运行时有调用呢?———刚学习完C语言后,对单片机的代码中最不可思议的就是中断调用。

1.什么是中断?
中断是指计算机在执行程序的过程中,当出现异常情况或特殊请求时,计算机停止现行程序的运行,转向对这些异常情况或特殊请求的处理,处理结束后再返回现行程序的间断处,继续执行原程序。
这里写图片描述
这个是51单片机的一个按键中断程序,是比较符合标准C语言的中断语法。在函数后面接interrupt与中断号。
2.我们现在看看cc2530的中断函数。
这里写图片描述
cc2530的中断服务函数与一般自定义函数不同,有特定的书写格式如下:中断向量是自己在串口初始化时候决定的。(具体是使用了什么串口的什么功能,在单片机的说明书上规定有对应的中断向量)
这里写图片描述
代码案例如下:



//接收中断处理函数 接收服务器信息
//1.进行电话唤醒,并且发送数据。2.对服务器发送的信息进行处理
#pragma vector=URX1_VECTOR
__interrupt void UART1_ISR()
{
  URX1IF=0;//清中断标志
  FromServer=U1DBUF;

  //电话远程唤醒
  if((int)U1DBUF==0x4E)//判断是否是电话唤醒的信息
  {
    U0CSR&=~0x40;
    U1CSR&=~0x40;//唤醒
    UartSendString(Lastdata_buf,11); //发送传感器姿态数据
    U1CSR|=0x40;
    U0CSR|=0x40;//睡眠
  }

  if((int)FromServer<0x21||(int)FromServer>0x28) return;//如果是废数据,舍弃;0x41A,0x48H,七个字母对应七个发送频率。
  sign_Server = 1;

  if(sign_Server)
  {
     switch((uint)FromServer)
    {
      case 0x21:  //5s !     
         DelayFromServer = 1;
        break;
      case 0x22://30s  " 
         DelayFromServer = 6; 
        break;
    case 0x23://1min #
        DelayFromServer =  10;
        break;
      case 0x24:  //10min   $   
        DelayFromServer = 116;
        break;
      case 0x25://1H %
        DelayFromServer = 694;
        break;
      case 0x26://4H  &
        DelayFromServer =  2782;
        break; 
      case 0x27:  //8H     '
        DelayFromServer = 5566 ;
        break;
      case 0x28:  //24H   (  
        DelayFromServer = 16702 ;
        break;
    }     
    sign_Server = 0;     
  }      
}

需要注意的是:它只是定义有些不同,但是像中断函数没有返回值,没有参数的规定是一样的。
(如有错误请不要生气,请多多指教。谢谢!)

展开阅读全文

CC2530无线中断接收问题

07-04

各位大虾,小弟初学zigbee,现在做了一个无线串口,问题是每次都只能进一次RF的接收中断,数据是正确的,接收到数据之后,连串口接收中断都进不去,全局只用了RF接收和串口接收中断,代码如下(两个班子烧同样的代码):rnrnrn#include "include.h"rn#include "wav.h"rn#include "cmd.h"rn#include "adc.h"rnrn#define T1Base (Fosc/128/1000) //1ms注意溢出rnuint T1TIME=300; //间隔时间长度rnuint T1COUNT=0;rnrnrnrn#define uint unsigned int rn#define uchar unsigned char rnrn#define Fosc 32000000rn//#define datalen 1//20440rnrnrn#define UART_CMD_LEN 3rnrnrnvoid Delay(uint temp);rnrnvoid RF_Init(void);//RF初始化rn//RF 发数 长度= UART_CMD_LENrnvoid RF_Send(char* CmdData);rnrnbit sendEN=0;rnrnrnrnrnchar txbuff[UART_CMD_LEN]=0x00;rnchar rxbuff[UART_CMD_LEN]=0x00;rnrnchar flag=0;rn/*UART0通信初始化rn-------------------------------------------------------*/rnvoid Uart0Init(void)rnrn//设置P0.2与P0.3时用rn// P0SEL |= 0x0C; //初始化UART0端口,设置P0.2与P0.3为外部设备IO口rn// PERCFG&= ~0x01; //选择UART0为可选位置一,即RXD接P0.2,TXD接P0.3rnrn P1SEL |= (1<<4)|(1<<5); //初始化UART0端口,设置P1.4与P1.5为外部设备IO口rn PERCFG|= (1<<0); //选择UART0为可选位置2,即RXD接P1.4,TXD接P1.5rnrn U0CSR = 0xC0; //设置为UART模式,并使能接受器rn rn U0GCR = 11;rn U0BAUD = 216; //设置UART0波特率为115200bpsrnrn URX0IE=1; //使能接受中断rn EA=1;rn rnrnrnrn/*UART0发送字符串rn-------------------------------------------------------*/rnvoid senduart0(unsigned char *Data,unsigned char len)rnrn unsigned char j=0;rn for(j=0;j>8;rn PAN_ID0=(PAN_ID);rn PAN_ID1=(PAN_ID>>8);rn EA=1;rn // RFST = 0xEd;rn RFST = 0xed; /* ISFLUSHRX */ // rn //RFST=0xED; rn RFST = 0xe3; /* ISRXON */ rn delay(12000); delay(12000); delay(12000); delay(12000); delay(12000); delay(12000); delay(12000); delay(12000); delay(12000); rn FRMFILT0&=~(1<<0);//禁止帧过滤 rn RFST = 0xED;//ISFLUSHRX() rn RFST = 0xE3;//ISRXON() rn rnrnrnrnrn//RF 发数 长度= UART_CMD_LENrnvoid RF_Send1(char* CmdData)rn rn unsigned char i; rn RFST = 0xe3; /* ISRXON */ rn /* wait for SFD not active and TX_Active not active */ rn while (FSMSTAT1 & ((1<<1) | (1<<5))); /* TX_ACTIVE | SFD */ rn RFIRQM0 &= ~(1<<6); /* disable RXPKTDONE interrupt */ rn IEN2 &= ~(1<<0); /* disable general RF interrupts */ rn RFST = 0xee; /* ISFLUSHTX */ rn RFIRQF1 = ~(1<<1); /* clear TXDONE interrupt */ rn //RFD = 0xA7; /* the first byte to TX is the length of the frame */ rn RFD=UART_CMD_LEN+2;rn for (i = 0; i < UART_CMD_LEN; i++) rn rn rn RFD = CmdData[i]; rn rn rn /* trun on RX interrupt */ rn RFIRQM0 |= (1<<6); IEN2 |= (1<<0); rn RFST = 0xe9; /* ISTXON */ rn while (!(RFIRQF1 & (1<<1))); /* waiting for transmission to finish */ rn RFIRQF1 = ~(1<<1); /* clear TXDONE interrupt */rnrnrnrnvoid RF_Send(char* CmdData)rn rn char i=0;rn// Uart0Send(1);rn RFST =0xEE; //清发送缓冲rnrn RFD=UART_CMD_LEN+2; //<<<<-----******注意rn for(i=0;i>8;rn T1CC0L=T1Base; //和晶振分频有关rn T1CCTL0|=(1<<2);rn T1CTL=0x0e; //128分频计数到T1CC0rn T1IE=0;rn EA=1;rnrnvoid T1_Interrupt(void) interrupt T1_VECTORrnrnif(T1STAT&(1<<5)!=0)rn rn T1COUNT++;rn if(T1COUNT>=T1TIME)rn rn sendEN=1;rn T1COUNT=0;rn rn rn rnrn//////////////////////////rnvoid main(void)rnrnrn //CLKCONCMD=0x80;rn EA=0;rn SLEEPCMD &= ~0x04; rn while(!(SLEEPSTA & 0x40)); rn CLKCONCMD &= ~0x47; rn SLEEPCMD |= 0x04; rn Uart0Init(); rn IEN2|=1<<4;rn rn rn //T1_Init();rn //T1IE=1;rn sendEN=0;rn rn RF_Init();rn EA=1;rnrn while(1)rn rn rn if(flag==1)rn rn rn RF_Send(txbuff); //启动一次发射rn flag=0;rn //RF_Init();rn rn rn rn rnrnrnrn 论坛

CC2530 数据收发,中断只能实现一次。

06-05

各位仁兄,我想通过最低层的寄存器操作,在节点1上发送数据,在节点2上通过中断读取数据。可是,现在的问题是,节点2只能发生一次中断,通过调试,可知这次中断中读到的数据是正确的,但之后再没有中断发生。请大侠帮我看看是什么地方的问题。节点1和节点2的程序如下,节点1发送,2接收。rn[code=c]rn#include "ioCC2530.h"rn#define led1 P1_0rn#define led2 P1_4rnrn#define uint8 unsigned charrn#define uint16 unsigned intrnrn#define RF_FCF_NOACK 0x8841 //不要求应答rn#define RF_FCF_ACK 0x8861 //要求接收方发送应答帧rn#define RF_NOACK_FLAGE 1 //不要求应答标志rn#define dest_PanID 0x0001rn#define dest_Addr 0x0001rn#define src_PanID 0x0001rn#define src_Addr 0x0002rnrnstatic uint8 RfPktHdr_Length=12;rnstatic uint8 buf[128];rnuint8 len=0; //帧长度rnstatic uint8 Len_Frame=0; //帧长度rnstatic uint8 rxMpdu[128]; //帧数据rnrntypedef struct rn uint8 packetLength; //包的长度rn uint8 fcf0; // Frame control field LSB帧控制域低字节rn uint8 fcf1; // Frame control field MSB帧控制域高字节rn uint8 seqNumber; //序列号rn uint16 destPanId; //目的PANIDrn uint16 destAddr; //目的地址rn uint16 srcPanId; //源PANIDrn uint16 srcAddr; //源地址rn rn RfPktHdr_t;rnrnvoid tx();rnvoid delay(uint16 time)rnrn uint16 i,j;rn for(i=0;i<=time;i++)rn rn for(j=0;j<=200;j++)rn rn rn rnrnrnvoid rf_init()//初始化rnrn FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */rnrn TXFILTCFG = 0x09;rn AGCCTRL1 = 0x15;rn FSCAL1 = 0x00;rnrn /* enable RXPKTDONE interrupt */rn RFIRQM0 |= (1<<6);rn /* enable general RF interrupts */rn IEN2 |= (1<<0);rnrn FREQCTRL = 0x0b; /* channel 11 */rnrn SHORT_ADDR0 = 0x05;rn SHORT_ADDR1 = 0x00;rn PAN_ID0 = 0x22; /* MUST set, or even can't receive broadcast message */rn PAN_ID1 = 0x00;rnrn RFST = 0xed; /* ISFLUSHRX */ // rn RFST=0xEC;rn RFST = 0xe3; /* ISRXON */rn delay(120);rn FRMFILT0&=~(1<<0);//禁止帧过滤rn RFST = 0xEC;//ISFLUSHRX()rn RFST = 0xE3;//ISRXON()rnrnrnrn#pragma vector=RF_VECTORrn__interrupt void rf_isr(void) //节点2中的主要功能函数rnrn unsigned char e, i;rn rn e = EA;rn EA = 0; /* disable global interrupt */rnrn if (RFIRQF0 & (1<<6)) rn len = RFD;rn len &= 0x7f;rn for (i = 0; i < len; i++) rn buf[i] = RFD;rn rn buf[i]='\0';rn led1 =!led1;rnrn rn RFIRQF0 &= ~0x40; /* clear RXPKTDONE interrupt */rn S1CON &=~0x03; /* clear general RF interrupt flag */rn // IEN2 &=~(1<<0);rn RFST=0xEC;rn EA = e; /* restore global interrupt state */rn // tx();rnrnrnuint8 MakeFrame(uint8 *data,uint8 length,uint8 seqNumber)//节点1发送前组帧rnrn RfPktHdr_t *RfHead;//帧头rn uint16 fcf;rn uint8 i;rn RfHead=(RfPktHdr_t*)rxMpdu;rn Len_Frame=RfPktHdr_Length+length;//帧的长度rn RfHead->packetLength=Len_Frame;rn fcf=(RF_NOACK_FLAGE) ? RF_FCF_NOACK : RF_FCF_ACK;rn RfHead->fcf0= fcf & 0xff;rn RfHead->fcf1= (fcf>>8) & 0xff;rn RfHead->seqNumber=seqNumber;rn RfHead->destPanId=dest_PanID;rn RfHead->destAddr=dest_Addr;rn RfHead->srcPanId=src_PanID;rn RfHead->srcAddr=src_Addr;rn for(i=0;i 论坛

中断调用

05-07

在MFC中,怎样调用中断?rn驱动以经写好,可以调用,但在MFC中不懂怎么调用。rn下面是我写好的调用,但出现了界面死机,主要问题在while(WAIT_OBJECT_0==WaitForSingleObject(hEvent,1000)) ,hEvent已在OnInitDialog中初始化和驱动关联,请问有没什么方法可以解决?详细点的。rnrn[code=C/C++][/code]void CTraffic_lightDlg::OnOK() rnrn rn UpdateData(TRUE); //读取数码管内容rn m_hy=m_hz=m_zs=m_zx=m_zt;rn if (m_hl>=m_zt || m_zl>=m_zt)rn rn AfxMessageBox("由于输入的时间错误,程序将终止");rn CDialog::OnCancel();rn //CTraffic_lightDlg::OnInitDialog();rn rn rn UpdateData(FALSE); //显示数码管内容rn rn n_zt=m_zt;rn LedShow(0);//横红纵绿rn //SetTimer(1,1,NULL);rn MapShow0();rn rn while(WAIT_OBJECT_0==WaitForSingleObject(hEvent,1000)) rn rn rn char t[256];rn CString s;rn n_zt-=1;rn n_s=n_zt/10;rn n_g=n_zt%10;rn LightTen(n_s);rn LightBit(n_g);rn //Sleep(1000);rn rn if(n_zt==-1)rn rn if(l_b==0)rn rn l_b=2;rn LedShow(1);//横绿纵红rn MapShow1();//SetTimer(2,1,NULL);//MapShow2();rn rn elsern rn l_b=0;rn LedShow(0);//横红纵绿rn MapShow0();//SetTimer(1,1,NULL);//MapShow0();rn rn rn n_zt=m_zt;rn rn if(n_zt==m_zl)rn rn if (l_b==0)rn rn MapShow3();//SetTimer(4,1,NULL);//MapShow3();rn LedShow(3);//横红纵黄rn rn rn rn rn rn if ( n_zt==m_hl) rn rn rn if (l_b==2)rn rn MapShow2();//SetTimer(3,1,NULL);//MapShow1();rn LedShow(2);//横黄纵红rn rn rn rn rn sprintf(t,"%d",n_zt);rn s=t;rn GetDlgItem(IDC_EDIT1)->SetWindowText(s); rn GetDlgItem(IDC_EDIT2)->SetWindowText(s);rn GetDlgItem(IDC_EDIT3)->SetWindowText(s);rn GetDlgItem(IDC_EDIT4)->SetWindowText(s);rn rn rn 论坛

调用9号中断调用16号中断的一些问题

01-13

[code=text]assume cs:code rnstack segmentrn dw 100 dup(0)rnstack endsrncode segment;主程序的功能为把shanqu1的程序(标号内的程序)写入软盘的扇区1 rn ;把shanqu2的程序(单独一个段)写入软盘的扇区2开始的区域rnstart: rnrn mov ax, stackrn mov ss,axrn mov sp,100rn rn mov ax,codern mov es,axrn mov bx,offset shanqu1;把shanqu1的程序写入软盘的扇区1rn rn mov al,1;写入1个扇区rn mov ch,0rn mov cl,1rn mov dl,0rn mov dh,0rn mov ah,3rn int 13hrn rn mov ax,shanqu2;把shanqu2的程序写入软盘的扇区2开始的区域rn mov es,axrn mov bx,0rn rn mov al,15;写入15个扇区rn mov ch,0rn mov cl,2rn mov dl,0rn mov dh,0rn mov ah,3rn int 13hrn mov ax,4c00hrn int 21hrnshanqu1:;写入扇区1rn mov ax,2000hrn mov es,axrn mov bx,0rn rn mov al,15rn mov ch,0rn mov cl,2rn mov dl,0rn mov dh,0rn mov ah,2rn int 13hrn rn mov ax,0rn mov [bx],axrn mov word ptr [bx+2],2000hrn jmp dword ptr [bx] rnshanqu1end:noprnrncode ends;主程序结束rnrnrnshanqu2 segment;写入扇区2开始的区域rn org 20000hrnassume cs:shanqu2rncall cleanrnjmp start1rn str1 db 'welcome',0rn str2 db '1) reset pc',0rn str3 db '2) start system',0rn str4 db '3) clock',0rn str5 db '4) set clock',0 rn str6 db 'Please input time like "yy/mm/dd hh:mm:ss.',0rn str7 db 'Set clock successful! Press enter key to return...',0 rn stack1 dw 128 dup(0)rnstart1: rn mov ax,csrn mov ss,axrn mov sp,offset stack1 +127rn mov ax,csrn mov ds,ax rn rn mov dh,1; ;显示主菜单-开始rn mov dl,1;rn mov cl,02hrn mov bx,offset str1rn call show_str;rn rn mov dh,12;rn mov dl,15rn mov cl,2hrn mov bx,offset str2 rn call show_strrn rn mov dh,14rn mov dl,15rn mov cl,2hrn mov bx,offset str3rn call show_strrn rn mov dh,16;rn mov dl,15;rn mov cl,2hrn mov bx,offset str4rn call show_str;rn mov dh,18;rn mov dl,15rn mov cl,2hrn mov bx,offset str5rn call show_str ;显示主菜单-结束rnshuru: mov ah,0 ;选择菜单:rn int 16h rn mov al,ahrn cmp al,5;rn ja shururn cmp al,2;扫描到的按键值大于5或小于2(输入1~4以外的字符)都需要重新输入rn jb shururn jmp short set1rn table0 db 0,1,2,3;对应0,1,2,3rn table1 db 2,3,4,5;1,2,3,4的案件通码rn set1:push bxrn mov bx,0rn s9:cmp al,table1[bx]rn je s8rn inc bxrn jmp s9rn s8:rn mov al,table0[bx] rn pop bx rn mov ah,al rn mov al,2 rn jmp setrn table dw sys_restart,sys_start,sys_showclock,sys_setclockrn set:push bxrn mov bl,ahrn mov bh,0rn add bx,bx;选择程序rn rn call word ptr table[bx] rnjmp quit rn;下面为4个子程序 rnsys_restart:;重新启动rn mov ax,0rn mov [bx],axrn mov word ptr [bx+2],0ffffhrn jmp dword ptr [bx] rn retrnrnsys_start:;正常启动计算机rn call cleanrn mov ax,0h rn mov es,axrn mov bx,7c00hrn rn mov al,2rn mov ch,0rn mov cl,1rn mov dl,80hrn mov dh,0rn mov ah,2rn int 13hrn rn mov ax,7c00hrn mov [bx],axrn mov word ptr [bx+2],0rn jmp dword ptr [bx] rn rn retrnrnsys_showclock:;显示时钟rn call cleanrn mov dl,2rn push csrn pop dsrn rn mov ax,0rn mov es,axrn rn mov si,offset int9rn mov di,204hrn mov cx,offset int9end-offset int9rn cldrn rep movsbrn rn push es:[9*4]rn pop es:[200h]rn push es:[9*4+2]rn pop es:[202h]rn rn clirn mov word ptr es:[9*4],204hrn mov word ptr es:[9*4+2],0rn stirn jmp sscrn rn int9:rn push axrn push bxrn push cxrn push esrn in al,60hrn rn pushfrn call dword ptr cs:[200h]rn rn cmp al,3bhrn jne nf1rn dec dlrn rn nf1:rn cmp al,1hrn jne int9retrn rn push es:[8000h];当这个中断不需要时,恢复原来的中断程序rn pop es:[9*4];不过有没有这个,对于本程序都没有影响rn push es:[8002h]rn pop es:[9*4+2]rnrn pop esrn pop cxrn pop bxrn pop axrnrn rn mov ax,2000hrn push axrn mov ax,0hrn push axrn retfrn rn rn int9ret:rn pop esrn pop cxrn pop bxrn pop axrn iretrn int9end:noprn fh db '// ::';用到的符号rn ssc: ;读取时钟,显示到屏幕上rn mov al,9rn out 70h,alrn in al,71hrn rn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn rn add al,30hrn add bl,30hrn rn mov es:[si+4],alrn mov byte ptr es:[si+5],dlrn mov es:[si+6],blrn mov byte ptr es:[si+7],dlrn rn mov al,fh[0]rn mov es:[si+10],alrn mov byte ptr es:[si+11],dlrnrn mov al,8rn out 70h,alrn in al,71hrn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn add al,30hrn add bl,30hrn rn push dxrn mov dx,0b800hrn mov es,dxrn pop dxrn mov si,160*2rn mov es:[si+16],alrn mov byte ptr es:[si+17],dlrn mov es:[si+18],blrn mov byte ptr es:[si+19],dlrn rn mov al,fh[1]rn mov es:[si+22],alrn mov byte ptr es:[si+23],dlrn rn mov al,7rn out 70h,alrn in al,71hrn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn add al,30hrn add bl,30hrn rn push dxrn mov dx,0b800hrn mov es,dxrn pop dxrn mov si,160*2rn mov es:[si+28],alrn mov byte ptr es:[si+29],dlrn mov es:[si+30],blrn mov byte ptr es:[si+31],dlrn mov al,fh[2]rn mov es:[si+34],alrn mov byte ptr es:[si+35],dlrn rn mov al,4rn out 70h,alrn in al,71hrn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn add al,30hrn add bl,30hrn rn push dxrn mov dx,0b800hrn mov es,dxrn pop dxrn mov si,160*2rn mov es:[si+40],alrn mov byte ptr es:[si+41],dlrn mov es:[si+42],blrn mov byte ptr es:[si+43],dlrn rn mov al,fh[3]rn mov es:[si+46],alrn mov byte ptr es:[si+47],dlrn rn mov al,2rn out 70h,alrn in al,71hrn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn add al,30hrn add bl,30hrn rn push dxrn mov dx,0b800hrn mov es,dxrn pop dxrn mov si,160*2rn mov es:[si+52],alrn mov byte ptr es:[si+53],dlrn mov es:[si+54],blrn mov byte ptr es:[si+55],dlrn rn mov al,fh[4]rn mov es:[si+58],alrn mov byte ptr es:[si+59],dlrn rn mov al,0rn out 70h,alrn in al,71hrn mov bl,alrn mov cl,4rn and bl,00001111brn shr al,clrn add al,30hrn add bl,30hrn rn push dxrn mov dx,0b800hrn mov es,dxrn pop dxrn mov si,160*2rn mov es:[si+64],alrn mov byte ptr es:[si+65],dlrn mov es:[si+66],blrn mov byte ptr es:[si+67],dlrn rn jmp sscrn retrn rnsys_setclock:;设置时钟rn call cleanrn mov dh,4;显示的行号rn mov dl,13;显示的列号rn mov cl,2hrn mov bx,offset str6rn call show_str;调用显示字符串函数rn startsc:jmp getstrrn string dw 50 dup(0);盛放输入的字符串rn getstr: mov ax,stringrn mov ds,axrn mov si,offset stringrn push axrn getstrs:mov ah,0rn int 16hrn cmp al,20hrn jb nocharrn mov ah,0rn call charstackrn mov ah,2rn call charstackrn jmp getstrsrn nochar: cmp ah,0ehrn je backspacern cmp ah,1chrn je enter1rn jmp getstrsrn backspace:mov ah,1rn call charstackrn mov ah,2rn call charstackrn jmp getstrsrn enter1: mov al,0;按enter键结束字符的输入rn mov ah,0rn call charstackrn mov al,[si][0];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][1]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,9rn out 70h,alrn mov al,blrn out 71h,alrn rn mov al,[si][3];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][4]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,8rn out 70h,alrn mov al,blrn out 71h,alrn rn mov al,[si][6];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][7]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,7rn out 70h,alrn mov al,blrn out 71h,alrn rn mov al,[si][9];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][10]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,4rn out 70h,alrn mov al,blrn out 71h,alrn rn mov al,[si][12];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][13]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,2rn out 70h,alrn mov al,blrn out 71h,alrn rn mov al,[si][15];把字符串解析后写入记录时钟的cmos ram中rn mov bl,[si][16]rn sub al,30hrn sub bl,30hrn mov cl,4rn shl al,clrn and al,11110000brn and bl,00001111brn add al,blrn mov bl,alrn mov al,0rn out 70h,alrn mov al,blrn out 71h,alrnrn mov dh,6;显示的行号rn mov dl,13;显示的列号rn mov cl,2hrn mov bx,offset str7rn call show_str;调用显示字符串函数 rn rn shuru1: mov ah,0rn int 16hrn cmp ah,1ch;rn jne shuru1;按enter键返回主程序rn rn mov top,0rn pop axrn mov ax,2000h;返回主程序rn push axrn mov ax,0hrn push axrn retf ;根据地址转移cpu执行位置rn rn retrn rn charstack:jmp short charstart;处理输入、输出、显示的子程序rn rn tablesr dw charpush,charpop,charshowrn top dw 0rn rn charstart:push bxrn push dxrn push dirn push esrn rn mov bx,csrn mov ds,bxrn mov si,offset stringrn cmp ah,2rn ja sretrn mov bl,ahrn mov bh,0rn add bx,bxrn mov dh,4rn mov dl,12rn jmp word ptr tablesr[bx]rn charpush:mov bx,toprn mov [si][bx],alrn inc toprn jmp sretrn charpop:cmp top,0rn je sretrn dec toprn mov bx,toprn mov al,[si][bx]rn jmp sretrn charshow:mov bx,0b800hrn mov es,bxrn mov al,160rn mov ah,0rn mul dhrn mov di,axrn add dl,dlrn mov dh,0rn add di,dxrn rn mov bx,0rn charshows:cmp bx,toprn jne noemptyrn mov byte ptr es:[di],' 'rn jmp sretrn noempty:mov al,[si][bx]rn mov es:[di],alrn mov byte ptr es:[di+2],' ' rn inc bxrn add di,2rn jmp charshowsrn sret:pop esrn pop dirn pop dxrn pop bxrn retrn rnclean:;清屏的子程序rn push bx;清屏rn push cxrn push esrn mov bx,0b800hrn mov es,bxrn mov bx,0rn mov cx,2000rn sub1s:mov byte ptr es:[bx],' 'rn add bx,2rn loop sub1srn pop esrn pop cxrn pop bxrn retrn ;显示字符串函数\/rnshow_str: rn push axrn push bxrn push cxrn push dxrn push esrn push sirn push cxrn mov al,160rn dec dhrn mul dhrn push axrn mov al,2rn dec dlrn mul dlrn pop sirn add si,axrn mov ax,0b800hrn mov es,axrn pop dxrn rn mov ch,0rn ;pop sirn rn s: mov cl,ds:[bx]rn jcxz okrn mov al,ds:[bx]rn mov es:[si],alrn mov es:[si+1],dlrn inc bxrn add si,2rn jmp short srn rn ok: rn pop sirn pop esrn pop dxrn pop cxrn pop bxrn pop axrn ret rn ;显示字符串函数^rnquit:rn mov ax,4c00hrn int 21hrnshanqu2 endsrnend start[/code]rn该程序的功能如下:rn1、列出功能选项,让用户通过键盘进行选择,界面如下:rn(1)reset pc ;重新启动计算机rn(2)start system ;引导现有的操作系统rn(3)clock ;进入时钟程序rn(4)set clock ;设置时间rn2、用户输入“1”后重新启动计算机rn3、用户输入“2”后引导现有的操作系统rn4、用户输入“3”后,执行动态显示当前日期、时间的程序。rn 当按下F1键后,改变显示颜色;按下Esc键后,返回到主菜单rn5、用户输入“4”后可更改当前的日期、时间,更改后返回主菜单rnrn问题1:这个程序中clock子程序中“变色”和“返回主菜单”功能是用更改9号中断程序实现的。问题是:当从clock项中返回主菜单后,再次进入clock项后F1和Esc按键都不管用且会阻止时间的刷新。这个是什么问题导致的?rnrn问题2:重新写clock的子程序,“变色”和“返回主菜单”功能由调用16号中断的1号功能实现。问题是:当进入clock项中变色超过15次(按键15次)后会出问题:时间不再刷新,继续按键的话会出现功能紊乱等问题。这个是什么问题导致的?rn程序代码在楼下: 论坛

没有更多推荐了,返回首页