原创 DSP2812串口设置及中断服务之C++程序

2008-9-8 02:01 1320 4 4 分类: 处理器与DSP

http://www.61ic.com


 


interrupt void ISRTxUart(void)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


{


    if (Uart.SendWritePtr != Uart.SendReadPtr)


    {


        SciaRegs.SCITXBUF = Uart.SendBuffer[Uart.SendReadPtr ++];


        Uart.SendReadPtr &= 0xff;


    }


    Uart.SendBusy = Uart.SendWritePtr != Uart.SendReadPtr;


    SciaRegs.SCIFFTX.bit.TXINTCLR = 1;


    PieCtrlRegs.PIEACK.bit.ACK9 = 1;


}


 


 


interrupt void ISRRxUart(void)


{


    Uart.ReceiveBuffer[Uart.ReceiveWritePtr ++] = SciaRegs.SCIRXBUF.all;


    Uart.ReceiveWritePtr &= 0xff;


    SciaRegs.SCIFFRX.bit.RXFFOVRCLR = 1;


    SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;


    PieCtrlRegs.PIEACK.bit.ACK9 = 1;


}


 


void UartObj::Init(void)


{


unsigned int i;


    for (i = 0; i < sizeof(ReceiveBuffer); i ++) {


        ReceiveBuffer = 0;


        SendBuffer = 0;


    }


    ReceiveWritePtr = 0;


    ReceiveReadPtr = 0;


    ReceivePosition = 0;


    ReceiveCount = 0;


    SendWritePtr = 0;


    SendReadPtr = 0;


    SendBusy = false;


    State = 0;


       


    EALLOW;


       GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4 = 1;


       GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5 = 1;


    EDIS;


    /* loopback   8 bit data */


    SciaRegs.SCICCR.all = 0x07;    // 1 bit stop, disable parity, idle mode, 8 bits data


   


    SciaRegs.SCICTL1.all = 0x03; // enable TX


    SciaRegs.SCICTL2.all = 0x03; //


   


    SciaRegs.SCIHBAUD = 0;


    SciaRegs.SCILBAUD = 0xf3;//SCI_PRD & 0xff;//0xF3;


   


    SciaRegs.SCICTL1.all = 0x23;


   


//    PieCtrlRegs.PIECRTL.bit.ENPIE = 1;   // Enable the PIE block


    PieCtrlRegs.PIEIER9.bit.INTx1 = 1;


    PieCtrlRegs.PIEIER9.bit.INTx2 = 1;


 


    /*设置中断服务程序入口地址*/


    EALLOW;    // This is needed to write to EALLOW protected registers


    PieVectTable.TXAINT = &ISRTxUart;


    PieVectTable.RXAINT = &ISRRxUart;


    EDIS;   // This is needed to disable write to EALLOW protected registers


 


    /*开中断*/


    IER |= M_INT9;


}


 


//KEY7压键事件处理


void KeyboardObj::Key17(void)


{


       System.BeepOn();


    Lcd.SetDisplayPos(2, 0);//汉字定位到上行左端


    Lcd.Display("KEY7键单击事件!!");


    Uart.puts("KEY7键单击事件");


}


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
4
关闭 站长推荐上一条 /3 下一条