-PROGRAMS= led-flash send-serial reply-serial nmra-stream
+PROGRAMS= led-flash send-serial reply-serial nmra-stream booster-output-low
include ../pic.make
debug macro debugvalue
movlw debugvalue
call debug_serial_transmit
-waitfortsr
- btfss TXSTA,1,0
- bra waitfortsr
endm
debug_serial_transmit
movwf TXREG,0 ; move contents of W (i.e. debugvalue)
; to TXREG for transmission
+waitfortsr
+ btfss TXSTA,1,0
+ bra waitfortsr
return
;****************************************************************************
bsf SPBRG,7,0
bsf SPBRG,0,0
+
+ debug 'a' ; write 'a' to serial port
;----------------------------------------------------------------------------
bcf T0CON,1,0 ; } prescale value 1:32
bsf T0CON,0,0 ; } (testing)
+ debug 'b' ; write 'b' to serial port
;----------------------------------------------------------------------------
; initialise buffers (for BSR5, for nmra from-serial/to-track buffers)
; all in access bank
+ debug 'c' ; write 'c' to serial port
;----------------------------------------------------------------------------
movwf TOTRACKBIT,0 ; make bit mask be 1000 0000
; initialise booster direction
- bsf TRISC,0,0 ; make pin 0 (booster direction) output
+ bcf TRISC,0,0 ; make pin 0 (booster direction) output
bcf PORTC,0,0 ; set low initially
; set booster pwm high
- bsf TRISC,1,0 ; make pin 1 (booster pwm) output
+ bcf TRISC,1,0 ; make pin 1 (booster pwm) output
bsf PORTC,1,0 ; booster pwm high
+ debug 'd' ; write 'd' to serial port
;----------------------------------------------------------------------------
; interrupt set-up
bsf INTCON,5,0 ; enable timer0 interrupts
+ debug 'e' ; write 'e' to serial port
;****************************************************************************
call led_green
; check which interrupt. Branch to serial_receive or timer or return
+ debug 146 ; write 'f' to serial port
btfss PIR1,5,0 ; check whether serial recv interrupt bit set
goto serial_receive
+ debug 147 ; write 'g' to serial port
btfss INTCON,2,0 ; check whether timer0 interrupt set
goto timer0_interrupt
goto panic
;****************************************************************************
serial_receive
+ debug 148 ; 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
advance_write_buffer
+ debug 149 ; write 'i' to serial port
; check if on 1st byte of new buffer anyway (i.e. last 4 bits = 0)
movf FROMSERIAL,0,0 ; copy FROMSERIAL pointer location to W
andlw 0xF ; investigate last 4 bits
timer0_interrupt
+ debug 150 ; write 'j' to serial port
bcf INTCON,2,0 ; clear interrupt-set bit
movlw 0x01 ; (testing)
; movlw 0x6E ; (not-testing)
movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us)
+ debug 151 ; write 'k' to serial port
; check next action - if 0, change to 1 and return
btfsc NMRACTRL,NEXTACTION,0
goto toggle_output
; if next action = 1, then toggle output
toggle_output
+ debug 152 ; write 'l' to serial port
btg PORTC,0,0 ; toggle booster output pin
btfss PORTC,0,0
goto decide_next_bit
; nextaction in preparation for 2nd half of bit and then return
mid_bit
+ debug 153 ; write 'm' to serial port
btfsc NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
btfss NMRACTRL,TRANSMITBIT,0
decide_next_bit
+ debug 154 ; write 'n' to serial port
; check whether current to-track buffer = current from-serial buffer
; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return)
read_from_buffer
+ debug 155 ; write 'o' to serial port
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
; set na=cb=bit value, advance bit (i.e. rotate TRANSMITBIT right),
; check if bit7, if so, advance byte, return
+ debug 156 ; write 'p' to serial port
movff TOTRACK,FSR1L ; set low byte of IND1 pointer
movlw 5
movwf FSR1H,0 ; set high byte of IND1 pointer
bra one_bit_to_track
zero_bit_to_track
+ debug 157 ; write 'q' to serial port
bcf NMRACTRL,TRANSMITBIT,0
bcf NMRACTRL,NEXTACTION,0
goto advance_bit
one_bit_to_track
+ debug 158 ; write 'r' to serial port
bsf NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
goto advance_bit
advance_bit
; rotate transmitbit to next position
+ debug 159 ; write 's' to serial port
rrncf TOTRACKBIT,1,0 ; rotate mask right
;*** surely rrnc (`rotate right not through carry' I assume)
;*** will leave a copy of the top bit in the N flag ? Then you
advance_pointer
+ debug 160 ; write 't' to serial port
; currently on bit 7 of the byte, after having read rest of byte to
; track; check whether it is 1 or 0
advance_read_buffer
+ debug 161 ; write 'u' to serial port
;*** I suggest swapping this and advance_read_byte round, since
;*** advance_read_byte is a more `inner' bit of the `loop' -iwj
advance_read_byte
+ debug 'v' ; write 'v' to serial port
; advance to next byte of buffer (increment TOTRACK)
; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT)
debug macro debugvalue
movlw debugvalue
call debug_serial_transmit
-waitfortsr
- btfss TXSTA,1,0
- bra waitfortsr
endm
debug_serial_transmit
movwf TXREG,0 ; move contents of W (i.e. debugvalue)
; to TXREG for transmission
+waitfortsr
+ btfss TXSTA,1,0
+ bra waitfortsr
return
;****************************************************************************
bsf SPBRG,7,0
bsf SPBRG,0,0
+
+ debug 'a' ; write 'a' to serial port
;----------------------------------------------------------------------------
bcf T0CON,1,0 ; } prescale value 1:32
bsf T0CON,0,0 ; } (testing)
+ debug 'b' ; write 'b' to serial port
;----------------------------------------------------------------------------
; initialise buffers (for BSR5, for nmra from-serial/to-track buffers)
; all in access bank
+ debug 'c' ; write 'c' to serial port
;----------------------------------------------------------------------------
movwf TOTRACKBIT,0 ; make bit mask be 1000 0000
; initialise booster direction
- bsf TRISC,0,0 ; make pin 0 (booster direction) output
+ bcf TRISC,0,0 ; make pin 0 (booster direction) output
bcf PORTC,0,0 ; set low initially
; set booster pwm high
- bsf TRISC,1,0 ; make pin 1 (booster pwm) output
+ bcf TRISC,1,0 ; make pin 1 (booster pwm) output
bsf PORTC,1,0 ; booster pwm high
+ debug 'd' ; write 'd' to serial port
;----------------------------------------------------------------------------
; interrupt set-up
bsf INTCON,5,0 ; enable timer0 interrupts
+ debug 'e' ; write 'e' to serial port
;****************************************************************************
call led_green
; check which interrupt. Branch to serial_receive or timer or return
+ debug 146 ; write 'f' to serial port
btfss PIR1,5,0 ; check whether serial recv interrupt bit set
goto serial_receive
+ debug 147 ; write 'g' to serial port
btfss INTCON,2,0 ; check whether timer0 interrupt set
goto timer0_interrupt
goto panic
;****************************************************************************
serial_receive
+ debug 148 ; 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
advance_write_buffer
+ debug 149 ; write 'i' to serial port
; check if on 1st byte of new buffer anyway (i.e. last 4 bits = 0)
movf FROMSERIAL,0,0 ; copy FROMSERIAL pointer location to W
andlw 0xF ; investigate last 4 bits
timer0_interrupt
+ debug 150 ; write 'j' to serial port
bcf INTCON,2,0 ; clear interrupt-set bit
movlw 0x01 ; (testing)
; movlw 0x6E ; (not-testing)
movwf TMR0L,0 ; set timer0 to 0x6E (so interrupt takes 58us)
+ debug 151 ; write 'k' to serial port
; check next action - if 0, change to 1 and return
btfsc NMRACTRL,NEXTACTION,0
goto toggle_output
; if next action = 1, then toggle output
toggle_output
+ debug 152 ; write 'l' to serial port
btg PORTC,0,0 ; toggle booster output pin
btfss PORTC,0,0
goto decide_next_bit
; nextaction in preparation for 2nd half of bit and then return
mid_bit
+ debug 153 ; write 'm' to serial port
btfsc NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
btfss NMRACTRL,TRANSMITBIT,0
decide_next_bit
+ debug 154 ; write 'n' to serial port
; check whether current to-track buffer = current from-serial buffer
; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return)
read_from_buffer
+ debug 155 ; write 'o' to serial port
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
; set na=cb=bit value, advance bit (i.e. rotate TRANSMITBIT right),
; check if bit7, if so, advance byte, return
+ debug 156 ; write 'p' to serial port
movff TOTRACK,FSR1L ; set low byte of IND1 pointer
movlw 5
movwf FSR1H,0 ; set high byte of IND1 pointer
bra one_bit_to_track
zero_bit_to_track
+ debug 157 ; write 'q' to serial port
bcf NMRACTRL,TRANSMITBIT,0
bcf NMRACTRL,NEXTACTION,0
goto advance_bit
one_bit_to_track
+ debug 158 ; write 'r' to serial port
bsf NMRACTRL,TRANSMITBIT,0
bsf NMRACTRL,NEXTACTION,0
goto advance_bit
advance_bit
; rotate transmitbit to next position
+ debug 159 ; write 's' to serial port
rrncf TOTRACKBIT,1,0 ; rotate mask right
;*** surely rrnc (`rotate right not through carry' I assume)
;*** will leave a copy of the top bit in the N flag ? Then you
advance_pointer
+ debug 160 ; write 't' to serial port
; currently on bit 7 of the byte, after having read rest of byte to
; track; check whether it is 1 or 0
advance_read_buffer
+ debug 161 ; write 'u' to serial port
;*** I suggest swapping this and advance_read_byte round, since
;*** advance_read_byte is a more `inner' bit of the `loop' -iwj
advance_read_byte
+ debug 'v' ; write 'v' to serial port
; advance to next byte of buffer (increment TOTRACK)
; (will be on bit 7 at this point anyway so no need to change TOTRACKBIT)