Hello.
I suggest that you use mr. Darrel Taylor's (fantastic) instant interrupts as mr. JohnMacklo proposed, but not from the link he provided which is for 18Fs only and you're using 16F. Instead start here: http://www.picbasic.co.uk/forum/showthread.php?t=3251
Here is an example of using mr. Taylor's USART interrupt to receive and send received, one byte at a time. However that is not the proper way to do it, you should use ISR only to collect data and get out of it as soon as possible. One of the usual methods is to create a buffer and fill it in ISR, and process received data when you can spare some time. It all depends on what you need. If you can tell us what would you like to achieve maybe we could assist you a little bit more.
In RX_ISR you can use HSERIN/OUT instead of directly reading RCREG and writting to TXREG, but accesing registers directly is a little bit faster I think. At least it uses less code space.Code:DEFINE OSC 20 @ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_ENABLE_ON & _DEBUG_OFF & _CP_OFF include "dt_ints-14.bas" RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 SPBRG = 129 ' 9600 Baud @ 20MHz, 0.16% DEFINE HSER_CLROERR 1 ' Clear overflow automatically x var byte ADCON0=%11000000 ADCON1=%00000111 porta=0 portb=0 portc=0 portd=0 porte=0 trisa=%00010000 trisb=%00000000 trisc=%10000001 trisd=%00000000 trise=%00000000 pause 200 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler RX_INT, _IHINFO, asm, yes endm INT_CREATE ; Creates the interrupt processor INT_ENABLE RX_INT ENDASM MAIN: 'do something here... goto MAIN RX_ISR: x=rcreg txreg=x @ INT_RETURN




Bookmarks