Serial recive is achived with the following code
;; Called from main interupt vector as RBO edge is only active interupt source ;; it came from there! ;; Soft UART - simplex :( ;; first recive a byte at the pre-set baud rate 8Data No Parity X stop _rx_byte: ; 5 ; well 3-4 (interupt latency) call _delay4 ; 4 ; delays 4 cycles total movlw 8 ; 1 ; 8data No parity x stop _rx_bit: bcf PORTA,B_RS232_CTS ; 1 ; drop CTS to stop any more ; bytes being sent while were ; dealing with this one call _delay_x_9 ; 2 ; RS_TICKS-9 bcf STATUS,C ; 1 ; skip1 PORTB,B_RS232_RxD ; 1 ; bsf STATUS,C ; 1 ; C:=RS232_RxD rrf RX_BYTE,F ; 1 ; addlw -1 ; 1 ; jnz _rx_bit ; 3 ; round for next bit
The explanation for this code is fairly simple.
RB0 is set up to generate an iterupt when it changes level from off to on. When this occours it causes this code to be entered (as per the comment). A deliberate delay of 9 instruction cycles is introduced. This is made up from two parts: The first is because our bit gathering loop has an overhead of 8 instructions after each sample (we are efectively sampling the start bit with the level change interupt). The second part is a single instruction overhead so we do not start our samples right on the start of each bit.
Part of this delay is used to set the number of bits to recive (8) in the w register.
The main sampling loop is then entered .