- #include "DSP28x_Project.h" // Device Headerfile and Examples Include
- // Prototype statements for functions found within this file.
- interrupt void cpu_timer2_isr(void);
- interrupt void SCITXINTA_isr(void); //发送
- interrupt void SCIRXINTA_isr(void); //接收
- void scia_fifo_init(void);
- void scia_init(void);
- void scia_xmit(int a);
- void scia_msg(char *msg);
- void shurushuchu_Gpio_Init(void);
- void toolInit(void);
- void DelayMs(Uint16 ms);
- // Global counts used in this example
- Uint16 LoopCount;
- Uint16 ErrorCount;
- Uint16 ReceivedChar;
- Uint16 SendChar;
- void main(void)
- {
- InitSysCtrl();//初始化系统时钟,关闭看门狗等
- InitSciaGpio();//初始化串口a使用的IO口
- shurushuchu_Gpio_Init();//初始化输入io,输出io,以及485芯片发送接收使能io(485DIR)
- DINT;//关闭中断
- InitPieCtrl();//初始化中断控制器
- IER = 0x0000;//禁止所有中断
- IFR = 0x0000;//清除中断标志位
- InitPieVectTable();//初始化中断向量表
- EALLOW;//解除保护
- PieVectTable.TINT2 = &cpu_timer2_isr;//将TINT2指向中断函数cpu_timer2_isr
- PieVectTable.SCITXINTA= &SCITXINTA_isr;
- PieVectTable.SCIRXINTA= &SCIRXINTA_isr;
- //PieVectTable.SCITXINTA = &SCITXINTA_ISR;
- EDIS; //关闭保护 , // 9.1 SCI-A
- InitCpuTimers(); //初始化CPU计时器
- ConfigCpuTimer(&CpuTimer2, 80, 80000); //80ms//
- CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
- /// IER |= M_INT1;// Enable CPU int1 which is connected to CPU-Timer 0,
- IER |= M_INT9;// CPU int13 which is connected to CPU-Timer 1,
- IER |= M_INT14;// CPU int 14, which is connected to CPU-Timer 2:
- // Enable TINT0 in the PIE: Group 1 interrupt 7
- PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
- PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
- PieCtrlRegs.PIEIER9.bit.INTx2= 1;
- IER = 0x100; // Enable CPU INT
- EINT; // Enable Global interrupt INTM 全局中断
- /// ERTM; // Enable Global realtime interrupt DBGM
- scia_fifo_init(); // 初始化串口a缓存模块
- scia_init(); // 初始化串口
- SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;//接收缓存溢出位清零
- while(1)
- {
- }
- }
- void DelayMs(Uint16 ms)
- {
- Uint16 i;
- for(i=0;i<ms;i++) DSP28x_usDelay(1000);
- }
- void scia_init()
- {
- SciaRegs.SCICCR.all =0x0007;
- //bit7 0 一个停止位 1 俩个停止位
- // 禁止奇偶校验
- //bit4 0 禁止自测 1 自测
- //bit3 空闲线多处理器模式
- //字符长度 8位
- SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
- // Disable RX ERR, SLEEP, TXWAKE
- SciaRegs.SCICTL2.all =0x0003;
- SciaRegs.SCICTL2.bit.TXINTENA =1;//使能发送准备中断
- SciaRegs.SCICTL2.bit.RXBKINTENA =1;//使能接收准备中断
- SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
- SciaRegs.SCILBAUD =0x0003;
- SciaRegs.SCICTL1.all =0x0023; //软件复位,重启SCI
- SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
- SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
- }
- void scia_xmit(int a) //发送字符
- {
- // while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
- SciaRegs.SCITXBUF=a;
- }
- void scia_msg(char * msg)//发送字符串
- {
- int i;
- i = 0;
- while(msg<i> != ' ')
- {
- scia_xmit(msg<i>);
- i++;
- }
- }
- // Initalize the SCI FIFO
- void scia_fifo_init()
- {
- SciaRegs.SCIFFTX.all=0xC022;
- SciaRegs.SCIFFRX.all=0x0022;
- SciaRegs.SCIFFCT.all=0x00;
- }
- void shurushuchu_Gpio_Init(void)
- {
- EALLOW;
- GpioCtrlRegs.GPAPUD.all = 0x000000000; //上拉
- GpioDataRegs.GPASET.all = 0x0000001ff; //复位高电平
- GpioCtrlRegs.GPAMUX1.all= 0x000000000; //配置为GPIO模式
- GpioCtrlRegs.GPADIR.all = 0x00000010f; //配置为输出模式
- EDIS;
- }
- interrupt void cpu_timer2_isr(void)
- {
- // DINT;//关闭总中断
- CpuTimer2Regs.TCR.bit.TSS = 1;//停止定时器
- CpuTimer2Regs.TCR.bit.TIF = 1;//清零中断标志位
- EALLOW;
- CpuTimer2.InterruptCount++;
- EDIS;
- GpioDataRegs.GPATOGGLE.bit.GPIO9=1;//翻转电平,切换接收发送模式
- if(GpioDataRegs.GPADAT.bit.GPIO9==1){SendChar=GpioDataRegs.GPADAT.bit.GPIO4+2*GpioDataRegs.GPADAT.bit.GPIO5
- +4*GpioDataRegs.GPADAT.bit.GPIO6+8*GpioDataRegs.GPADAT.bit.GPIO7;
- //组合IO电平为0x 0 0 0 0 io7 io6 io5 io4
- scia_xmit(SendChar);//发送字符
- }
- CpuTimer2Regs.TCR.bit.TRB = 1;//定时器重装
- CpuTimer2Regs.TCR.bit.TSS = 0;//启动定时器
- EINT; //开总中断
- }
- interrupt void SCIRXINTA_isr(void)
- {
-
- ReceivedChar = SciaRegs.SCIRXBUF.all;
- GpioDataRegs.GPADAT.bit.GPIO0=~(ReceivedChar|0x01);//电平逻辑与控制逻辑相反;需要进行位取反运算
- GpioDataRegs.GPADAT.bit.GPIO1=~(ReceivedChar|0x02);//电平逻辑与控制逻辑相反;需要进行位取反运算
- GpioDataRegs.GPADAT.bit.GPIO2=~(ReceivedChar|0x04);//电平逻辑与控制逻辑相反;需要进行位取反运算
- GpioDataRegs.GPADAT.bit.GPIO3=~(ReceivedChar|0x08);//电平逻辑与控制逻辑相反;需要进行位取反运算
- SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear SCI Interrupt flag
- PieCtrlRegs.PIEACK.all|=0x100;
- EINT; //开总中断
- }
- interrupt void SCITXINTA_isr(void)
- {
- if(GpioDataRegs.GPADAT.bit.GPIO9==1)
- {SendChar=GpioDataRegs.GPADAT.bit.GPIO4+2*GpioDataRegs.GPADAT.bit.GPIO5
- +4*GpioDataRegs.GPADAT.bit.GPIO6+8*GpioDataRegs.GPADAT.bit.GPIO7;
- //组合IO电平为0x 0 0 0 0 io7 io6 io5 io4
- scia_xmit(SendChar);//发送字符
- }
- SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear SCI Interrupt flag
- PieCtrlRegs.PIEACK.all|=0x100;
- EINT; //开总中断
- }
- //===========================================================================
- // No more.
- //===========================================================================
- </i></i>
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>