我不懂C的,要说不懂,也还算看得懂一点,所以以前玩AVR,51都是靠BASCOM。
说实话BASCOM和 KEIL 都各有所长,如果是专业的话,C当然是最好的,业余的话,比起从头开始学C,我还是推荐BASIC
大话不说了,mikro 是一个系列,他包含了PIC,AVR,和51,但是重点还是MIKRO PIC上。
无论是C,或是B,还是P 语言,都很多程度上方便了业余工作者。
http://www.mikroe.com/en/download/
我用MIKROBASIC 做了个 WAVPLAYER,以下为I2S部分,内容源于C30的I2S部分,其他部分尚未完成。“ '为注释符”
'#define FCY 67737600 '22.5792*3
'#define FS 44100
'#define FCSCK 64*FS
'#define BCG_VAL 767 '(FCY/(2*FS))-1
dim TxBuffA as word[512] absolute 0x4000
dim TxBuffB as word[512] absolute 0x4400
dim _SD_RAM as byte[2]
dim DMA_Flag_A as byte
dim _error as word
sub procedure initI2sBuff
memset(@TxBuffA,0,512)
memset(@TxBuffB,0,512)
end sub
sub procedure i2s_Init
'//DCI Control Register DCICON1 Initialization
DCICON1.10=0
'DCICON1bits.CSCKD = 0; // Serial Bit Clock (CSCK pin) is output
DCICON1.9=1
'DCICON1.9=0
'DCICON1bits.CSCKE = 0; // Data changes on rising edge sampled on falling edge of CSCK
DCICON1.8=0
'DCICON1bits.COFSD = 0; // Frame Sync Signal is output
DCICON1.7=0
'DCICON1bits.UNFM = 0; // Transmit ?抯 on a transmit underflow
DCICON1.6=0
'DCICON1bits.CSDOM = 0; // CSDO pin drives ?抯 during disabled transmit time slots
DCICON1.5=0
'DCICON1bits.DJST = 0; // Data TX/RX is begun one serial clock cycle after frame sync pulse
DCICON1.1=0
DCICON1.0=1
'DCICON1bits.COFSM = 1; // Frame Sync Signal set up for I2S mode
'DCICON1 = 0x101
'// DCI Control Register DCICON2 Initialization
DCICON2.11=0
DCICON2.10=0
'DCICON2bits.BLEN = 0; // One data word will be buffered between interrupts
DCICON2.8=0
DCICON2.7=0
DCICON2.6=0
DCICON2.5=1
'DCICON2bits.COFSG = 1; // Data frame has 2 words viz., LEFT & RIGHT samples
DCICON2.3=1
DCICON2.2=1
DCICON2.1=1
DCICON2.0=1
'DCICON2bits.WS = 15; // Data word size is 16 bits
'DCICON2 = 0x2F
'// DCI Control Register DCICON3 Initialization
' DCICON3 = BCG_VAL; // Set up CSCK Bit Clock Frequency
DCICON3=5
'// Transmit Slot Control Register Initialization
TSCON.0=1
' TSCONbits.TSE0 = 1; // Transmit on Time Slot 0
TSCON.1=1
' TSCONbits.TSE1 = 1; // Transmit on Time Slot 1
'TSCON=3
'//Receiver Slot Control Register Initialization
'RSCON.0=1
' RSCONbits.RSE0 = 1; // Receive on Time Slot 0
'RSCON.0=1
' RSCONbits.RSE1 = 1; // Receive on Time Slot 1
'RSCON=3
'// Force First two words to fill-in buffer/shift register
'DMA0REQ.15=1
'DMA0REQbits.FORCE=1;
' while(DMA0REQbits.FORCE==1);
'DMA0REQ.15=1
'While DMA0REQ.15=1
'nop
'wend
' DMA0REQbits.FORCE=1;
' while(DMA0REQbits.FORCE==1);
'// Disable DCI Interrupt and Enable DCI module
IFS3.12=0
' IFS3bits.DCIIF=0;
IEC3.12=0
' IEC3bits.DCIIE=0;
end sub
sub procedure dma0_Init
DMA0CON=0x2002
DMA0CON.15 = 0
'DMA0CONbits.CHEN = 0; //Disable
DMA0CON.14 = 0
'DMA0CONbits.SIZE = 0; //Word
DMA0CON.13 = 1
'DMA0CONbits.DIR = 1; //Read From DPSRAM, write to peripheral
DMA0CON.12 = 0
'DMA0CONbits.HALF = 0; //Block Transfer Int is caused at FULL moved
DMA0CON.11 = 0
'DMA0CONbits.NULLW = 0; //Null write to peripheral
DMA0CON.5 = 0
DMA0CON.4 = 0
'DMA0CONbits.AMODE = 0; //Register indirect with Post-Increment
DMA0CON.1 = 1
DMA0CON.0 = 0
'DMA0CONbits.MODE = 0x02; //Continuous, ping-pong mode enabled
DMA0CNT = 511 '//Transfer count, Frame - 1
DMA0REQ.15=0
'DMA0REQbits.FORCE = 0; //Register indirect with Post-Increment
DMA0REQ = 60
'DMA0REQbits.IRQSEL = 0x003C; //Select DCI Codec
DMA0PAD = 0x0298
'//Periferal Address = DCI TXBUF 0
DMA0STA= 0x4000
DMA0STB= 0x4400
'DMA0STA= __builtin_dmaoffset(dci1TxBuffA); //Page A buffer address
'DMA0STB= __builtin_dmaoffset(dci1TxBuffB); //Page B buffer address
end sub
sub procedure dma0_start
IFS0.4 = 0
'IFS0bits.DMA0IF = 0; // Clear DMA interrupt
IEC0.4 = 1
'IEC0bits.DMA0IE = 1; // Enable DMA interrupt
DMA0CON.15 = 1
'DMA0CONbits.CHEN = 1; // Enable DMA Channel
end sub
sub procedure i2s_start
DCICON1.15 = 1
'DCICON1bits.DCIEN = 1;
end sub
sub procedure i2s_stop
DCICON1.15 = 0
'DCICON1bits.DCIEN = 0;
end sub
sub procedure intdma0 org 0x00001C
DMA_Flag_A = 1 ';//notice to main.c
IFS0.4=0
end sub
sub procedure fillbuffer
if DMA_Flag_A = 1 then
if DMACS1 = 1 then
for _error = 0 to 255
Mmc_Fat_Read(_SD_RAM[0])
Mmc_Fat_Read(_SD_RAM[1])
TxBuffA[ 2*_error ] = _SD_RAM[0] + (_SD_RAM[1] << 8)
Mmc_Fat_Read(_SD_RAM[0])
Mmc_Fat_Read(_SD_RAM[1])
TxBuffA[ 2*_error+ 1] = _SD_RAM[0] + (_SD_RAM[1] << 8)
next _error
else
for _error = 0 to 255
Mmc_Fat_Read(_SD_RAM[0])
Mmc_Fat_Read(_SD_RAM[1])
TxBuffB[ 2*_error ] = _SD_RAM[0] + (_SD_RAM[1] << 8)
Mmc_Fat_Read(_SD_RAM[0])
Mmc_Fat_Read(_SD_RAM[1])
TxBuffB[ 2*_error+ 1] = _SD_RAM[0] + (_SD_RAM[1] << 8)
next _error
end if
end if
DMA_Flag_A = 0
end sub
end.
一周热门 更多>