I'm trying to generate a pulse train on PORTB of a 18F2455. I had a simple Idea of running a loop and incrementing the port number, but this gives me an 'argument out of range message. Does anyone know how to do this properly?
I've just listed "channel" in a cblock and set it to 0 before this loop
Code:
Step
BSF PORTB, channel ; Set output channel high
CALL Wait ; Delay
BCF PORTB, channel ; Clear output channel
CALL Wait ; Delay
INCF channel
; If channel > 7 make it 0
MOVF channel, W ; Copy channel value to W for testing
SUBWF 8, W ; Subtract W from 8
BTFSC STATUS, Z ; Check if result is Zero (channel needs to be reset)
CLRF channel ; Reset to zero
GOTO Step
Here's the code I used for anyone who might need it..
"maxChannel" is an 8-bit value representing how many channels should be pulsed before the loop restarts. 10000000 being 8 channels, while 00000001 is just one.
"channel" is the currently selected channel using the same logic as above.
Code:
Start
CALL ResetChannels ; Reset to channel 1
Step
MOVF channel, W ; Copy channel selection
MOVWF PORTB ; SET outputs to selected channel combo
CALL Wait ; Delay
CLRF PORTB ; Clear outputs
CALL Wait ; Delay
RLNCF channel ; Increment Channel
; If channel > maxChannels reset to 1
MOVF channel, W ; Copy channel value to W for testing
MOVWF L4
RRNCF L4 ; Go back one because of previous increment
MOVF L4, W
SUBWF maxChannel, W ; Subtract W from maxChannel
BTFSC STATUS, Z ; Check if result is Zero (channel needs to be reset)
CALL ResetChannels ; Reset to channel 1
GOTO Step ; ELSE do next channel
ResetChannels
MOVLW b'00000001' ; Start with Channel 1
MOVWF channel
RETURN