(i.e. the first two complete bytes should be 01111111 01111111)
(packets beginning with some other sequence are reserved for non-NMRA messages)
-Maximum NMRA message length = 16 bytes (i.e. 112 bits).
+Maximum NMRA message length = 15 bytes (i.e. 105 bits).
Messages longer than this will cause things to get confused at the moment.
baud rate 9600
; macro to call subroutine to transmit over serial port for debugging
; takes 8-bit value, puts in W, invokes debug_serial_transmit
+
+ ifndef SLOW_VERSION
+debug macro debugvalue
+ endm
+ endif
+ ifdef SLOW_VERSION
debug macro debugvalue
movlw debugvalue
call debug_serial_transmit
endm
+ endif
debug_serial_transmit
movwf TXREG,0 ; move contents of W (i.e. debugvalue)
; timer0 initial config for NMRA timer
+
+ ifdef SLOW_VERSION
bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode (testing)
-; bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing)
+ endif
+
+ ifndef SLOW_VERSION
+ bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing)
+ endif
+
bcf T0CON,5,0 ; timer0 use internal clock
bcf T0CON,3,0 ; use prescaler
-; bcf T0CON,2,0 ; }
-; bcf T0CON,1,0 ; } prescale value 1:2
-; bcf T0CON,0,0 ; } (not-testing)
+ ifndef SLOW_VERSION
+ bcf T0CON,2,0 ; }
+ bcf T0CON,1,0 ; } prescale value 1:2
+ bcf T0CON,0,0 ; } (not-testing)
+ endif
+
+ ifdef SLOW_VERSION
bsf T0CON,2,0 ; }
bcf T0CON,1,0 ; } prescale value 1:16
bcf T0CON,0,0 ; } (testing)
+ endif
debug 'b' ; write 'b' to serial port
;----------------------------------------------------------------------------
;****************************************************************************
serial_receive
- debug 'h' ; write 'h' to serial port
+; debug 'h' ; write 'h' to serial port
movff FROMSERIAL,FSR0L ; set low byte of INDF0 pointer
movlw 5
movwf FSR0H,0 ; set high byte of INDF0 pointer
- debug '1' ; write 'h' to serial port
+; debug '1' ; write 'h' to serial port
movff RCREG,INDF0 ; copy to received register
- debug '2' ; write 'h' to serial port
- incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte
- debug '3' ; write 'h' to serial port
-; *** check for overrun and do something sensible
+; debug '2' ; write 'h' to serial port
+
+; check whether bit 7 is set. If so, move to next buffer.
btfsc INDF0,7,0 ; check if bit 7 is set
call advance_write_buffer ; if so, move to next buffer
- debug '4' ; write 'h' to serial port
+; debug '3' ; write 'h' to serial port
+
+; If not, move to next byte
+ btfss INDF0,7,0 ; check if bit 7 is set
+ incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte
+; debug '4' ; write 'h' to serial port
retfie 1
; *** I *think* the interrupt bit is cleared by reading out of RCREG
debug ',' ; write 'j' to serial port
bcf INTCON,2,0 ; clear interrupt-set bit
+
+ ifdef SLOW_VERSION
movlw 0x01 ; (testing)
-; movlw 0x6E ; (not-testing)
+ endif
+
+ ifndef SLOW_VERSION
+ movlw 0x6E ; (not-testing)
+ endif
+
movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us)
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
- btfsc TOTRACKBIT,7,0
- debug '4'
btfsc TOTRACKBIT,7,0
rrncf TOTRACKBIT,1,0 ; rotate mask right
bra one_bit_to_track
zero_bit_to_track
- debug 'q' ; write 'q' to serial port
+ debug '_' ; write 'q' to serial port
+ debug '0' ; write 'q' to serial port
+ debug '_' ; write 'q' to serial port
bcf NMRACTRL,TRANSMITBIT,0
bcf NMRACTRL,NEXTACTION,0
goto advance_bit
one_bit_to_track
- debug 'r' ; write 'r' to serial port
+ debug '_' ; write 'q' to serial port
+ debug '1' ; write 'r' to serial port
+ debug '_' ; write 'q' to serial port
bsf NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
goto advance_bit
movwf FSR1H,0
; if set, move to next buffer
- btfsc INDF1,7,0
- debug 'F'
btfsc INDF1,7,0
call advance_read_buffer
; if not set, move to next byte of samebuffer (increment TOTRACK)
; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT)
- btfss INDF1,7,0
- debug 'Y'
btfss INDF1,7,0
incf TOTRACK,1,0
return
; macro to call subroutine to transmit over serial port for debugging
; takes 8-bit value, puts in W, invokes debug_serial_transmit
+
+ ifndef SLOW_VERSION
+debug macro debugvalue
+ endm
+ endif
+ ifdef SLOW_VERSION
debug macro debugvalue
movlw debugvalue
call debug_serial_transmit
endm
+ endif
debug_serial_transmit
movwf TXREG,0 ; move contents of W (i.e. debugvalue)
; timer0 initial config for NMRA timer
+
+ ifdef SLOW_VERSION
bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode (testing)
-; bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing)
+ endif
+
+ ifndef SLOW_VERSION
+ bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing)
+ endif
+
bcf T0CON,5,0 ; timer0 use internal clock
bcf T0CON,3,0 ; use prescaler
-; bcf T0CON,2,0 ; }
-; bcf T0CON,1,0 ; } prescale value 1:2
-; bcf T0CON,0,0 ; } (not-testing)
+ ifndef SLOW_VERSION
+ bcf T0CON,2,0 ; }
+ bcf T0CON,1,0 ; } prescale value 1:2
+ bcf T0CON,0,0 ; } (not-testing)
+ endif
+
+ ifdef SLOW_VERSION
bsf T0CON,2,0 ; }
bcf T0CON,1,0 ; } prescale value 1:16
bcf T0CON,0,0 ; } (testing)
+ endif
debug 'b' ; write 'b' to serial port
;----------------------------------------------------------------------------
;****************************************************************************
serial_receive
- debug 'h' ; write 'h' to serial port
+; debug 'h' ; write 'h' to serial port
movff FROMSERIAL,FSR0L ; set low byte of INDF0 pointer
movlw 5
movwf FSR0H,0 ; set high byte of INDF0 pointer
- debug '1' ; write 'h' to serial port
+; debug '1' ; write 'h' to serial port
movff RCREG,INDF0 ; copy to received register
- debug '2' ; write 'h' to serial port
- incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte
- debug '3' ; write 'h' to serial port
-; *** check for overrun and do something sensible
+; debug '2' ; write 'h' to serial port
+
+; check whether bit 7 is set. If so, move to next buffer.
btfsc INDF0,7,0 ; check if bit 7 is set
call advance_write_buffer ; if so, move to next buffer
- debug '4' ; write 'h' to serial port
+; debug '3' ; write 'h' to serial port
+
+; If not, move to next byte
+ btfss INDF0,7,0 ; check if bit 7 is set
+ incf FROMSERIAL,1,0 ; advance FROMSERIAL pointer by 1 byte
+; debug '4' ; write 'h' to serial port
retfie 1
; *** I *think* the interrupt bit is cleared by reading out of RCREG
debug ',' ; write 'j' to serial port
bcf INTCON,2,0 ; clear interrupt-set bit
+
+ ifdef SLOW_VERSION
movlw 0x01 ; (testing)
-; movlw 0x6E ; (not-testing)
+ endif
+
+ ifndef SLOW_VERSION
+ movlw 0x6E ; (not-testing)
+ endif
+
movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us)
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
- btfsc TOTRACKBIT,7,0
- debug '4'
btfsc TOTRACKBIT,7,0
rrncf TOTRACKBIT,1,0 ; rotate mask right
bra one_bit_to_track
zero_bit_to_track
- debug 'q' ; write 'q' to serial port
+ debug '_' ; write 'q' to serial port
+ debug '0' ; write 'q' to serial port
+ debug '_' ; write 'q' to serial port
bcf NMRACTRL,TRANSMITBIT,0
bcf NMRACTRL,NEXTACTION,0
goto advance_bit
one_bit_to_track
- debug 'r' ; write 'r' to serial port
+ debug '_' ; write 'q' to serial port
+ debug '1' ; write 'r' to serial port
+ debug '_' ; write 'q' to serial port
bsf NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
goto advance_bit
movwf FSR1H,0
; if set, move to next buffer
- btfsc INDF1,7,0
- debug 'F'
btfsc INDF1,7,0
call advance_read_buffer
; if not set, move to next byte of samebuffer (increment TOTRACK)
; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT)
- btfss INDF1,7,0
- debug 'Y'
btfss INDF1,7,0
incf TOTRACK,1,0
return