导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→串口不能中断[guest]

 *第24829篇: 串口不能中断

  
楼 主:guest 2004年8月18日10:22
 串口不能中断
在进行89c52仿真时,发送等基本功能正常,但就是不能产生串口中断,反复检查了硬件觉得没问题,请问出现该问题的可能情况有哪些?请高手们畅所欲言。谢谢!
email:nameyang@126.com。
  
2楼:bingzhi 2004年8月18日15:59
 开中断了吗?

tr1=1;///tr2=1,根据波特率设置
es=1;
ea=1;
  
3楼:nameyang 2004年8月18日16:11
 监测已经开中断了,但还是不行
监测已经开中断了,但还是不行
  
4楼:bingzhi 2004年8月23日16:59
 #inlcude "at89c52.h"
#inlcude "at89c52.h"

#define  COMM_TIMEOUT 0xff

unsigned char g_ch=0;
unsigned char g_flag=0;
void InitComm()
{
            

            T2CON=0x30;            
                            RCAP2H=255;
                            RCAP2L=184;
                       
            
            SCON=0x50;
            ES=1;
            EA=1;
            TR2=1;
}

////////////////////////////////////////////
//function:Receive 1 byte
//return:0--ok  1---failure
unsigned char ReadComm(unsigned char *ch)
{

        unsigned int timeout = COMM_TIMEOUT;
       

        timeout = COMM_TIMEOUT;
        while(timeout--)//µ÷ÊÔÍê³Éºó£¬ÇëʹÓó¬¹ýʱ
        {

        
             if(RI==1)
             {
                 RI=0;
                 for(i=0;i  <5;i++)
                 {

        
                 }
                 *ch = SBUF;
                 RI=0;
                 return ID_OK;
             }
        }
        return   ID_ERR;
}
////////////////////////////////////////////
//function:Send 1 byte
//return:0--ok  1---failure
unsigned char WriteComm(unsigned char ch)
{
        unsigned int xdata timeout=COMM_TIMEOUT;

        

        SBUF=ch;
        while(timeout--)
        {
             if(TI==1)
             {
                 TI=0;
                 return ID_OK;
             }
        
        }
        return ID_ERR;
}
//
void  Comm_ISR() interrupt 4
{
          

     ES=0;
     if(RI==1)
     {
                ReadComm(&g_ch);
                g_flag=1;
                
    }
    ES=1;

}

void main(void)
{
        unsigned char xdata testbuf[100]="12345678901234567890";
        unsigned char xdata command=0;


       g_flag=0;

        InitComm();//Baud9600);
        SendResponse(0x01,testbuf,3);
        
        EA=1;
        ES=1;
        
        while(1)
        {
         if(g_flag)
         {
          g_flag=0;
          WriteCom(g_ch);
         }
        }
}      


/////////////////////////////////////////////
对照一下程序,如果有问题,可能就是你的RXD线没有接通,
或者,你的+5V电源没有接对。


>>>>>>对该主题发表你的看法

本主题贴数4,分页: [第1页]


[上一篇主题]:请教贴片电阻的问题

[下一篇主题]:招聘版主