Voici un exemple de programme pour les derniers microcontrôleur type PIC18F25K42 ( avec DMA et USART en mode DMX)
ce qui permet de generer des trames DMX sans consommation de cycle horloge ...
Code:uint8_t DMX1[513]; uint16_t i; uint16_t CTU1; uint8_t txLength; void main(void) { // asm ("BANKSEL PRLOCK"); asm ("MOVLW 0x55"); asm ("MOVWF PRLOCK"); asm ("MOVLW 0xAA"); asm ("MOVWF PRLOCK"); asm ("BSF PRLOCK, 0"); SYSTEM_Initialize(); INTERRUPT_GlobalInterruptEnable(); //Initialize the Arrays for(i=0; i<514 ; i++) { DMX1[i] = i; //DMX_Console_Transmit (11, *Array1) } DMA1_Initialize(); //Initialize DMA1 DMA1SSA = &DMX1; //Set source start address DMA1DSA = (uint8_t) &U1TXB; //Set destination start address to U1TXB DMA1CON1bits.SMR = 0b00; //Choose PFM space as source memory DMA1CON1bits.SMODE = 0b01; //Increment source address each transaction DMA1CON1bits.DMODE = 0b00; //Remain unchanged the destination address transaction DMA1SSZL = 0x00; //Set 9 bytes for source size DMA1SSZH = 0x02; DMA1DSZ = 0x01; //Set 1 byte for destination size DMA1CON1bits.SSTP = 0b1; //SIRQEN is clear after sending 9 bytes DMA1CON1bits.DSTP = 0b0; //No destination reload stop bit DMA1SIRQ = 28; //Choose U1TX as Transfer Trigger Source DMA1AIRQ = 31; DMA1CON0bits.DMA1SIRQEN = 1; //Source Trigger is allowed to start DMA transfer DMA1CON0bits.AIRQEN = 1; DMA1CON0bits.DMA1EN = 1; //Enable DMA while (0 == PIR2bits.DMA1DCNTIF){} //Wait after message transfer completed DMA1SSA = &DMX1; INTERRUPT_GlobalInterruptEnable(); DMX1[1]=255; TMR0_StartTimer(); while (1) { if (PORTBbits.RB0) { DMX1[1]=255; } else { DMX1[1]=0; } } }
-----