evandude
New Member
Hi, I just have a quick question about this code.
I have modified it slightly to fit my needs. originally it was simulated open-drain (output low or set as input (hi-z) for high)
I (hopefully) switched it to 'regular' output.
the other thing is that it LOOKS like the output should be normally high, and active low with this code. that is the polarity that I need for the max232.
I'd just appreciate if anyone who's familiar with assembly could take a quick look and verify that my change is going to give me what I want.
I wouldn't ask, but it's a big pain to test this because the circuit needs to be plugged into my car stereo to function at all and so it takes a lot of time and effort to test out small code changes, so i'd like to get a second opinion on this code before i go through that again.
thanks in advance.
This is the original version:
And here is my modified version:
I have modified it slightly to fit my needs. originally it was simulated open-drain (output low or set as input (hi-z) for high)
I (hopefully) switched it to 'regular' output.
the other thing is that it LOOKS like the output should be normally high, and active low with this code. that is the polarity that I need for the max232.
I'd just appreciate if anyone who's familiar with assembly could take a quick look and verify that my change is going to give me what I want.
I wouldn't ask, but it's a big pain to test this because the circuit needs to be plugged into my car stereo to function at all and so it takes a lot of time and effort to test out small code changes, so i'd like to get a second opinion on this code before i go through that again.
thanks in advance.
This is the original version:
Code:
SerialSend9600:
bcf SPIO, SerialTX9600 ; not quite sure why this is needed...
bcf INTCON, GIE ; disable interrupts, timing critical code
;; initially send start bit
LowBit9600:
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bcf STRISIO, SerialTX9600 ; set pin as output/drain (low)
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
call Wait23
call Wait23
call Wait23
call Wait23
goto $+1 ; 94
BitCount9600:
incf sendbitcount, f ; 1
btfsc STATUS, Z ; 1 2 exit loop if we've sent 8 bits already
goto StopBit9600 ; 2
rrf sendreg, 1 ; 1 load next bit into carry flag
btfss STATUS, C ; 1 2
goto LowBit9600 ; 2
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bsf STRISIO, SerialTX9600 ; set pin as input/open collector (high)
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
call Wait23
call Wait23
call Wait23
call Wait23
nop
goto BitCount9600 ; 2
StopBit9600:
nop
nop
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bsf STRISIO, SerialTX9600 ; set pin as input/open collector (high)
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
bsf INTCON, GIE ; enable interrupts, timing critical code done
call Wait24
call Wait24
call Wait24
call Wait24 ; 96
return
Code:
SerialSend9600:
bsf SPIO, SerialTX9600 ; not quite sure why this is needed...
bcf STRISIO, SerialTX9600 ; set pin as output
bcf INTCON, GIE ; disable interrupts, timing critical code
;; initially send start bit
LowBit9600:
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bcf SPIO, SerialTX9600
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
call Wait23
call Wait23
call Wait23
call Wait23
goto $+1 ; 94
BitCount9600:
incf sendbitcount, f ; 1
btfsc STATUS, Z ; 1 2 exit loop if we've sent 8 bits already
goto StopBit9600 ; 2
rrf sendreg, 1 ; 1 load next bit into carry flag
btfss STATUS, C ; 1 2
goto LowBit9600 ; 2
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bsf SPIO, SerialTX9600 ;set output pin high
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
call Wait23
call Wait23
call Wait23
call Wait23
nop
goto BitCount9600 ; 2
StopBit9600:
nop
nop
bsf STATUS, RP0 ; select data bank 1
ERRORLEVEL -302
bsf SPIO, SerialTX9600 ; set output pin high
ERRORLEVEL +302
bcf STATUS, RP0 ; go back to data bank 0
bsf INTCON, GIE ; enable interrupts, timing critical code done
call Wait24
call Wait24
call Wait24
call Wait24 ; 96
return