这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » DSP2812串口设置及中断服务之C++程序

共2条 1/1 1 跳转至

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

菜鸟
2008-08-28 16:36:12     打赏


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键单击事件");
}

 




关键词: DSP2812     串口     设置     中断     服务     程序    

菜鸟
2008-09-12 23:47:45     打赏
2楼

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]