Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

serial assembly question

Status
Not open for further replies.

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:
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
And here is my modified version:
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
 
46 views... oookay.... well if it makes things any simpler, all i've changed is swapping the lines setting the pin as input to setting the pin high, and some additions to the init to initialize the pin as an output, in the high state to start with.... I just want to know if i've done it correctly...
 
i cant help ya out on this question, because i am new to pic assembly language.
but i have done assembly on intel chips , the Z80, and a course in ibm 370 assembly language.
I can tell you this , if you are not sure of why they used a particular piece of code , then how can you predict the output. You HAVE to be sure WHY they did what they did,or you cant be sure of the output.
sorry if this sounds like a lecture, i know you are asking for help. :oops:
just my two cents.
 
I don't think that really applies here. i know what the author of the program was doing, and i can see what each part of the program is doing. i'm just trying to change the code to fit with my hardware (which is already assembled) so that it is a regular serial output, versus open drain. my question isn't concerning the overall operation of the code. Just like when I was learning spanish, with a new language it's usually a lot easier to read than it is to write your own stuff at first. I can read assembly and understand what's going on for the most part but I have little to no experience actually writing anything in PIC assembly. That's why i'm asking.

all i am trying to verify is that

A) my initialization will indeed initialize the I/O pin to be an output, and start off with it in a high state.
B) my change further on will make it so that at the spots in the original program where the pin would be switched to an input for a high-impedance state, it will now instead drive the pin high, leaving it as an output.

I am just trying to get someone to verify that the couple lines of actual code that I wrote in there are going to do what I think.
 
Alright, nevermind I guess. after a bunch of looking over the datasheet for the 12F629 i also discovered that TRISIO and GPIO are in different data banks, so my modified code needed to reflect that... so i'm guessing either nobody's reading this thread, or nobody's bothering to respond... I guess i will just try to BS the code as best I can and hope it works.
 
evandude said:
Alright, nevermind I guess. after a bunch of looking over the datasheet for the 12F629 i also discovered that TRISIO and GPIO are in different data banks, so my modified code needed to reflect that... so i'm guessing either nobody's reading this thread, or nobody's bothering to respond... I guess i will just try to BS the code as best I can and hope it works.

It might have helped if you'd mentioned what processor it was for?, I presumed an 18F series from the unusual registers?.

You might also try looking at my tutorial RS232 code, which is designed for normal RS232.
 
Status
Not open for further replies.

Latest threads

Back
Top