打印

串口中断函数形式是什么样的

[复制链接]
4109|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
power5000|  楼主 | 2007-9-4 16:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
斑竹,有没有串口中断接收发送程序模块或者例子让我看看? 我现在不知道中断程序是怎么写的?
在51中设置好相关寄存器,* void int0(void) interrupt 0 这样的形式去进入哪个中断?
在ARM中概念应该是一样的吧,但是不知道具体的函数形式是什么样的!!例如:
void __irq Key_Int(void),是__irq 这个标识进中断函数的吗?那串口中断呢??
void __UART Int(void)是这样吗?呵呵,我觉得我自己很可爱

问的问题比较菜,谢谢!

相关帖子

沙发
dld2| | 2007-9-4 20:05 | 只看该作者

呵呵

串口中断处理函数,定义大概是 void __irq uart0_int(void)。
要想让处理器知道这个是串口中断服务程序,你要把这个函数的地址告诉中断处理系统,并且说明是用来处理uart0中断的。不同的处理器,这一步的做法不一样。
你要说明你用的是什么芯片,并且和系统的初始化程序还有关系。

使用特权

评论回复
板凳
阿南| | 2007-9-4 20:44 | 只看该作者

给您放个s3c2410中串口作为485的初始化各中断程序

/*******************************************************************************************
函数原形:void Uart1_Init_Rec(int pclk,int baud)
功能描述:当工作在接收模式下时,初始化UART1(485)
参    数:无            
*******************************************************************************************/
void Uart1_Init_Rec(int pclk,int baud)
{
    int i;
    if (pclk == 0)
    pclk = PCLK;

    rUFCON1=0x0;     //FIFO disable
    rUMCON1=0x0;     //AFC disable

    rULCON1=0x33;    //8位数据,1位停止位,第9位(奇偶位)强制为1 
    rUCON1=0x105;    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
 
    rUBRDIV1=( (int)(pclk/16./baud) -1 );//bps = 38400
    
    pISR_UART1=(unsigned)Uart1_RXInt_LT1200;
    rSRCPND=BIT_UART1;
    rINTPND=BIT_UART1;
    rSUBSRCPND=BIT_SUB_RXD1;//清除RXD1,ERR1中断挂起标志位

    rINTMSK &=~(BIT_UART1);    //去除UART中断屏蔽
    rINTSUBMSK &=~(BIT_SUB_RXD1);//去除子中断屏蔽
    for(i=0;i<100;i++);
}

/*******************************************************************************************
函数原形:void __irq Uart0_RXInt_LT1200(void)
功能描述:LT1200 485接收中断处理程序
参    数:无    
*******************************************************************************************/
void __irq Uart1_RXInt_LT1200(void)
{
    char buffer[6]={2,4,0,0,0,0};
    unsigned short JoinNum,Value,i;
    if (((rUTRSTAT1&0x1)>0) && (rUERSTAT1==0))
    {
        ch=~rURXH1;
        if(_9bit==0)
        {//Parity Check as 0
            if(ch==0x00)                 //分隔符
            {//Next Command Start
                gState=0xfe;//ff:no active ,fe:active,fd:got id,00~f0:get how many receive buf
            }
        }
        else
        {
            if(gState==0xfe)
            {//接收的第一个字符
                gReceiveID=ch;
                if(ch==0xff)
                {//接收到复位指令(FF 02 03 00)  或查询网络型号指令(FF 02 03 01 ID 00)
                    gState=0xfc;
                    gReceiveLen=0;
                }
                else
                {//接收到ID,
                    gState--;//gState = fd
                }
            }
            else if(gState==0xfd)//ID XX
            {
                if(ch==00)
                {//ID 00 主机空闲
                    gState=0xfe;
                    if(gReceiveID==h_config->NetID)    //just search me to input
                    {
                        gMyTimeOut=0;
                        gReceive00Time=0;    //the pgm2 have searched me ,so I work properly.
                        if(pSendHead!=pSendTail)
                        {
                            buffer[2]=(unsigned char)pSendHead->JoinNum;
                            buffer[3]=(unsigned char)(pSendHead->JoinNum>>8);
                            buffer[4]=(unsigned char)pSendHead->Value;
                            buffer[5]=(unsigned char)(pSendHead->Value>>8);
                            if(++pSendHead==(Sendbuf+50))pSendHead=Sendbuf;
                            Send_485(buffer,6);
                        }
                        else Send_485("x2x0",2);
                    }
                }
                else
                {//接收到信息,ID LEN
                    gReceiveLen=ch;
                    gState=0;
                }
            }
            else if(gState==0xfc)//接收到复位指令(FF 02 03 00)  或查询网络型号指令(FF 02 03 01 ID 00)
            {
                switch(gReceiveLen)
                {
                    case 0:
                            if(ch==0x02) gReceiveLen++;//FF 02
                            else gState=0xff;//错误无效
                            break;
                    case 1:
                            if(ch==0x03) gReceiveLen++;//FF 02 03
                            else gState=0xff;
                            break;
                    case 2:
                            if(ch==0x01) gReceiveLen++;//FF 02 03 01
                            else if(ch==0x00)          //FF 02 03 00 = 复位
                            {
                //                            HardReset();//接收到主机的复位指令(FF 02 03 00)
                //                Uart_Printf("  Receive = FF 02 03 00");
                //                Uart_Printf("  Reset");
                            }    //reset
                            else gState=0xff;
                            break;
                    case 3:
                            gReceiveID=ch;             //FF 02 03 01 ID
                            gReceiveLen++;
                            break;
                    case 4:
                            if(ch==00)                 //FF 02 03 01 ID 00
                            {//查询网络型号指令(FF 02 03 01 ID 00)    
                                gMyTimeOut=0;                                              
                                gState=0xfe;    //search net device
                                if(gReceiveID==h_config->NetID)
                                {
                                //    Delay(1);
                                    Send_485(SERIES,14);
                                }
                            }
                            else gState=0xff;
                            break;
                }
            }
            else if(gState!=0xff)//ID LEN Value
            {//接收到信息
                gMyTimeOut=0;//when geting long data ,ignore the time out.
                ReceiveBuffer[gState++]=ch;
                if(gReceiveLen==gState)
                {
//                    rULCON1=0x3b;    //reset to get 00;//Parity forced as 0,Command end
                    if(gReceiveID==h_config->NetID)        //control me
                    {
                        gState=0xfe;
                        JoinNum=ReceiveBuffer[1];
                        JoinNum<<=8;
                        JoinNum+=ReceiveBuffer[0];
                        pTaskTail->JoinNum=JoinNum;
                        if(JoinNum>1999)
                        {
                            Uart_SendByte(JoinNum);
                            pTaskTail->Value=gReceiveLen-2;
                            pTaskTail->pBuf=pStringBuf;
                            for(i=0;i<gReceiveLen;i++)
                            {
                                *pStringBuf=ReceiveBuffer[i+2];
                                if(++pStringBuf==(StringBuf+1024))pStringBuf=StringBuf;
                            }
                        }
                        else if(JoinNum>999)
                        {
                            Value=ReceiveBuffer[3];
                            Value<<=8;
                            Value+=ReceiveBuffer[2];
                            pTaskTail->Value=Value;
                        }
                        else
                        {
                            Uart_SendByte(JoinNum);
                            if(ReceiveBuffer[2]==0x00)Value=1;
                            else Value=0;
                            pTaskTail->Value=Value;
                        }
                        if(++pTaskTail==(Taskbuf+50))pTaskTail=Taskbuf;
//                        TestVal[2] = executeevent.animatedTimer - TestVal[0];
                    }
                }
            }
        }
    }
    rSRCPND=BIT_UART1;
    rINTPND=BIT_UART1;
    rSUBSRCPND=BIT_SUB_RXD1;//清除RXD1,ERR1中断挂起标志位
}

使用特权

评论回复
地板
阿南| | 2007-9-4 20:48 | 只看该作者

要注意:pISR_UART1=(unsigned)Uart1_RXInt_LT1200;

想要更深入,就去分析启动代码吧!祝顺利

使用特权

评论回复
5
power5000|  楼主 | 2007-9-5 09:03 | 只看该作者

谢谢

认真学习中^

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

37

主题

81

帖子

1

粉丝