Hi,
I just made a quick and dirty test here using DT_Ints. The Main routine waits for PortB.0 going low, when it does it enables the TX interrupt. The TX interrupt service routine extracts characters from the buffer array and puts them in the TX register of the USART. When it sees a CR it disables the interrupt.
Seems to work here, try it out if you like.Code:'**************************************************************** '* Name : HWTX.BAS * '* Author : Henrik Olsson * '* Notice : Copyright (c) 2010 Henrik Olsson 2010 * '* : All Rights NOT Reserved - use as you see fit. * '* Date : 2010-11-16 * '* Version : 0.0 * '* Notes : Test for interrupt based USART transmit using * '* : DT_ints-18 on a 18F4520 * '**************************************************************** DEFINE LOADER_USED 1 ' We're using a bootloader DEFINE OSC 20 ' 20Mhz x-tal is used DEFINE HSER_BAUD 38400 ' Baudrate is 38400 CMCON = 7 ' Comparators OFF ADCON1 = %00001111 ' No analog inputs TRISC.7 = 1 ' RxPin is input TRISC.6 = 0 ' TxPin is output TRISB.0 = 1 ' PortB.0 is input TxBuffer VAR BYTE[128] ' Transmit buffer array. TxPointer VAR Byte ' Pointer into the above array INCLUDE "DT_INTS-18.bas" ' Include Darrels interrupt engine. INCLUDE "ReEnterPBP-18.bas" ' And the stub needed for interrupts in PBP ASM ; Set up the USART transmit interrupt. INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TX_INT, _USART_TX, PBP, no endm INT_CREATE ; Creates the interrupt processor ENDASM Boot: HSEROUT ["Program start",13] ' A dummy HSEROUT here to init the USART and show we're alive. ' Now load the array with something we want to send. The string is, in this case, terminated with a CR (13). ArrayWrite TxBuffer,["This is the TX Array Buffer and we're sending it with an interupt based routine",13] Main: If PortB.0 = 0 then ' PortB.0 going low is what TxPointer = 0 ' Initialize pointer to beginning of array @ INT_ENABLE TX_INT ; Enable USART TX interrupt Pause 100 ' Simple debounce for the button ENDIF Goto Main ' And do it again. USART_TX: TXREG = TxBuffer[TxPointer] ' Load character from array into USART TX register If TxBuffer[TxPointer] = 13 then ' If that character was a CR we're done so we..... @ INT_DISABLE TX_INT ; ...disable the any further USART TX interrupts. ELSE ' If the character was not a CR we..... TxPointer = TxPointer + 1 ' ...increase prepare to send the next character. ENDIF @ INT_RETURN ; And exits the interrupt.
/Henrik.




Bookmarks