標(biāo)題: 如何利用按鍵控制fir和func函數(shù)的接入,附單片機(jī)程序 [打印本頁(yè)]

作者: xxtianjing    時(shí)間: 2020-5-9 22:59
標(biāo)題: 如何利用按鍵控制fir和func函數(shù)的接入,附單片機(jī)程序
#include "my_include.h"
int DataGeted=0;                                //數(shù)據(jù)已生成標(biāo)記
unsigned int numTransfers_Tx=0;        //發(fā)送數(shù)據(jù)塊數(shù)計(jì)數(shù)器(中斷中使用)
int BlockCnt=0;                                        //處理數(shù)據(jù)塊數(shù)計(jì)數(shù)器(驅(qū)動(dòng)3D0發(fā)光管閃動(dòng))

int KeyDownFlag;
int KeyDownCnt;
int dat,xx;

//函數(shù)聲明
extern void fir();                                        //fir
extern void initial_sys();                                //系統(tǒng)初始化(I2C McBSP AIC23 EDMA EMIF etc.)
extern void func();

//Block Data Send interrupt function
//interrupt period=240/48000=0.005s=5ms
long DMARec_p;
interrupt void DMA_tx_Isr()
{
        numTransfers_Tx++;
        DataGeted=1;
        //修改DMA2源地址,并啟動(dòng)DMA2
   *DMA_CSR2=(*DMA_CSR2)&(0xfff7);//clear FRAME trasmited flag, B3 ,清除幀中斷
        if((numTransfers_Tx&0x0001)==1)
        {
           *DMA_CSSA_U2 =((long)BufferB*2)>>16;                                //通道目的起始地址Upper 數(shù)據(jù)地址為0x20000
           *DMA_CSSA_L2 =(unsigned int)((long)BufferB*2);                                //通道目的起始地址Low
                DMARec_p = BufferA;
        }
        else
        {
           *DMA_CSSA_U2 =((long)BufferA*2)>>16;                                //通道目的起始地址Upper 數(shù)據(jù)地址為0x20000
           *DMA_CSSA_L2 =(unsigned int)((long)BufferA*2);                                //通道目的起始地址Low
                DMARec_p = BufferB;
        }
   *DMA_CCR2 =0x1986;        //通道使能,不重復(fù),利用McBSP1發(fā)送事件進(jìn)行同步
        LBDS1=~uLED[(numTransfers_Tx>>5)&0x7];
}

//Light on/off LED 3D0 to display the Pragram is Running
void BlinkLed(int Flag)
{
        if(Flag==0)
//                *IODATA=(*IODATA)|(1<<6);//B6=1, GPIO6=1, Light off LED
            *IODATA=(*IODATA)&0xffbf;//B6=0, GPIO6=0, Light on LED
        else
                *IODATA=(*IODATA)&0xffbf;//B6=0, GPIO6=0, Light on LED
}




void main(void)
{
        initial_sys();        //初始化
//標(biāo)紅部分自己弄的,想用key1控制fir和func函數(shù)的調(diào)用,但是怎么改都不成,想法是這樣子的:按key1,數(shù)碼管()就是func的函數(shù))會(huì)從0...9閃爍,fir也就成功接入了
        while(1)
        {
                if(KeyDownFlag==1)
        {
          KeyDownCnt--;
                if(KeyDownCnt==0)
                        KeyDownFlag=0;
        }
        dat=keyboard & 0x00ff;
        if((dat!=0xff)&&(KeyDownFlag==0))//some key is down
        {
                KeyDownFlag=1;
                KeyDownCnt=200;        //200*5ms=1s
                if(dat==0xf7)         //key1 is down
                        xx=1;
        }

                if(DataGeted==1&&xx==1)//處理周期為5ms(48000/240=200Hz)
                {
                        xx=0;

                        DataGeted=0;
                        *IODATA=(*IODATA)&0xff7f;//B7=0, GPIO7=0, 23J0=1, for test CPU use ratio
                        BlinkLed((BlockCnt/100)%2);        //控制3D0已1Hz的頻率閃動(dòng)
                        BlockCnt++;

                                fir();
                            func();


                        *IODATA=(*IODATA)|(1<<7);//B7=1, GPIO7=1, 23J0=0, for test CPU use ratio
                }//Block data Getted
        }//while(1)
}


作者: xxtianjing    時(shí)間: 2020-5-10 12:46
我標(biāo)題打錯(cuò)了,想問(wèn)大家知道怎么利用按鍵控制的,我沒(méi)有弄出來(lái)啊




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1