PDA

View Full Version : 16F877a Interupt driven Hserin



RFsolution
- 1st November 2006, 21:22
Hi all, after suffering with my previous problem I was wondering if someone
has a sample code to do some interupt driven Hserin

I need to do the following:

Read a serial string at 9600bd containing a start command "#" then 5 variables of each 3 Decimal digits separated by a ";" (let's say byte in decimal presentation)

then I need to read 5 AD values on RA0-RA4
Then i need to write those variables to an LCD display 4x20)
and send them back and to some the serial port using HSEROUT
finally I need to write some variables or bits to some hardware
ports like (PortB,PortE,PortD)

Mean while I may receive an updated string on the serial port using HSERIN

If I use the following example from Mister E to play with Hserin and interupt
it works,


' Serial communication definition
' ===============================
' Using internal USART and MAX232 to interface to PC
'
RCSTA = $90 ' enable serial port,
' enable continuous receive
'
TXSTA = $24 ' enable transmit,
' BRGH=1
'
SPBRG = 103 ' set baudrate to 2400

' Alias definition
' ================
'
'
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
OERR var RCSTA.1 ' Overrun error
CREN var RCSTA.4 ' Continuous receive

' Hardware initialisation
' =======================
'
'
pause 10 ' safe start-up delay

Main:
if oerr then ' Overrun error?
cren=0 ' clear it
cren=1
endif

if RCIF then ' incomming data?
TXREG=RCREG ' take it, send it
while TXIF=0 ' wait untill transmit buffer is empty
wend
endif
goto main


But as soon as I add multiple commands like Hserout,LCDout,etc...

I miss some values on the HSERIN or get stucked on the "WAIT" command

Any help or example how to do a proper interupt driven HSERIN while
still displaying on the LCd and HSEROUT ?

mister_e
- 2nd November 2006, 17:46
I doubt that a tight loop and a register polling method will work. try working around the example 2 of this one
http://www.picbasic.co.uk/forum/showpost.php?p=8601&postcount=11
In the ISR you may set a flag to tell the main to read the ADCs. To avoid waste of time and void some interrupts, i would recommend to set/read the ADCs register instead of using ADCIN. A short asm Delay loop, or use internal timer, OR a tight PAUSEUS x loop for your acquisition time.

The use of instant interrupts OR asm, could be the best and smarter choice. Rule #1, never waste your time in ISR... this is what 'Wait' do ?.

Let us know what's happen now.

Darrel Taylor
- 3rd November 2006, 00:38
if someone has a sample code to do some interupt driven Hserin
Quite a few...
http://www.picbasic.co.uk/forum/search.php?do=process&query=rcif
--and--
http://list.picbasic.com/cgi-bin/board-search.cgi?searchwhere=ALL&query=rcif