-
Usart interrupt
Hello everybody,
After many search, I hope find here a solution to my problem.
I'm using the PIC16F877, and I would like
1) Receive a byte through USART interrupt,
2) During these interrupt sendback a byte with the usart.
The first point here above can be esaly done, eg :
http://www.picbasic.co.uk/forum/arch...hp/t-3068.html
But how can I perform the 2nd point because the HSERIN and HSEROUT command are not available in case of using the hardware serial interrupt???
May be by using the simple software serout command, but is not the realy best method.....
WKR, thony
-
Try using DT instant interrupts.
It worked for me.
http://darreltaylor.com/DT_INTS-18/home.html
-
Will this work??
Code:
DISABLE
USART_INT:
RCSTA=0 ' disable serial port
'bla bla bla
RCSTA=$90 ' re-start serial port
HSEROUT SOMETHING
RESUME
ENABLE
-
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.
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
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.