
Originally Posted by
Mike, K8LH Is that 17 instruction cycles for 3X bit rate interrupt driven RX only code? If so, that's incredible... I'd very much like to see your code Sir...
I counted wrong, it's 18 cycles. However, the modified code is only 16. Here's the original code.
Code:
RecSkips equ 20h
InByte equ 21h
Cache equ 22h
TransferFlags equ 23h
#define RS232In PORTB,2
decfsz RecSkips,F
goto DoneRS232
btfss TransferFlags,b_receiving
goto get_start_bit
bsf STATUS,C
btfss b_RS232In
bcf STATUS,C
rrf InByte,F
movlw 3
movwf RecSkips
btfss STATUS,C
goto DoneRS232
movf InByte,W
movwf Cache
bsf TransferFlags,b_byte_available
bcf TransferFlags,b_receiving
goto DoneRS232
get_start_bit incf RecSkips,F; set to 1
btfsc b_RS232In
goto DoneRS232
movlw 4
movwf RecSkips
bsf TransferFlags,b_receiving
movlw 80h
movwf InByte
DoneRS232
It does away with the need to keep a count of bits received by setting the received byte to 80h. When the last bit is shifted into InByte then the carry will be set. This makes it a lot quicker.
To make it multi channel, I found it easier to write a macro for each channel. To make sure that the timing is accurate, PORTB is read at the beginning of the interrupt and stored in a temporary variable.
Here's the macro
Code:
ReceiveChannel Macro chan
rrf PortTemp,F
decfsz RecSkips+chan,F
goto DoneRS232#v(chan)
btfss b_receiving,chan
goto g_strt#v(chan)
rrf InByte+chan,F
movlw 3
movwf RecSkips+chan
btfss STATUS,C
goto DoneRS232#v(chan)
movf InByte+chan,W
movwf cache+chan
bsf b_byte_avail,chan
bcf b_receiving,chan
goto DoneRS232#v(chan)
g_strt#v(chan) incf RecSkips+chan,F; set to 1
btfsc STATUS,C
goto DoneRS232#v(chan)
movlw 4
movwf RecSkips+chan
bsf b_receiving,chan
movlw 80h
movwf InByte+chan
DoneRS232#v(chan)
endm
And this is the code that would go in the interrupt routine.
Code:
bcf PIR1,CCP1IF; reset special event trigger interupt
movfw PORTB; read all channels at once
movwf PortTemp
ReceiveChannel 0
rrf PortTemp,F; skip bit 1
rrf PortTemp,F; skip bit 2
ReceiveChannel 1
ReceiveChannel 2
ReceiveChannel 3
ReceiveChannel 4
ReceiveChannel 5
With the above code, if a byte is received on channel 3 (or any of 0 to 5), bit 3 of b_byte_avail will be set and the byte will be in cache+3.
Mike.