新闻  |   论坛  |   博客  |   在线研讨会
DSP2812串口设置及中断服务之C++程序(转)
beibeidong | 2008-05-07 16:12:08    阅读:5423   发布文章

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

 

interrupt void ISRTxUart(void)
{
    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[i] = 0;
        SendBuffer[i] = 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键单击事件");
}

点击开大图

 

 

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客