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.

Help with a concept [PIC12F629]

Status
Not open for further replies.

Gnome

New Member
I just started fiddling with a PIC 12F629 and was curious as to which way is best to send data out the GPIO,0 ( pin 7 ) that is stored in say W_TEMP. Right now I'm clearing the C bit in OPTION_REG and rotating the LSB on W_TEMP and then rotate C into GPIO. This seems messy...

Code:
bcf OPTION,0
movlw CODE
movwf W_TEMP
rrf W_TEMP,1
rlf GPIO,1
goto L0006     ; Delay function

What I am noticing in my simulator that GPIO,1 is also changing states; however it is set to an input. That is why this seems messy to me.

Is there a better way to shift 8 bits on to GPIO from W_TEMP?

Thanks

*Edit - I only want to shift the bits on to GPIO,0. One bit at a time of course.

-Ken
 
Last edited:
Code:
    movlw     8
movwf    loop
btfss       temp,0
goto        $+5
bsf          gpio,1
goto       $+4
rrf         temp,1
goto       $-5
bcf         gpio,1
call        delay
rrf          temp,1
decfsz    loop,1
goto       $-.10
(exit)
 
Last edited:
Hi Gnome,

I'm confused with your request. "OPTION,0" is used for pre-escaler settings when using internal timer0.

You are willing to "clearing the C bit in OPTION_REG ", but in your code you are clearing the bit 0 of the OPTION register. Your code should read "bcf STATUS,0" instead.

Also you should verify if the port is correctly configured as you wish. As this is a multi-purpose communication port, by default bits <2:0> are not defined as logical I/O but as internal comparators. You should force the I/O behaviour for these bits by doing

movlw 0x07
movwf CMCOM

as described in the datasheet of the componet.

Hope this will help you.

In addition, you may know this practical tutorial
Gooligum Electronics
 
Code:
    movlw     8
movwf    loop
btfss       temp,0
goto        $+5
bsf          gpio,1
goto       $+4
[COLOR="red"]rrf         temp,1
goto       $-5[/COLOR]
bcf         gpio,1
call        delay
rrf          temp,1
decfsz    loop,1
goto       $-.10
(exit)

What a horrible bit of code (and formatting). What do the instructions in red do?

Try,
Code:
	movlw	8
	movwf	count
Loop	btfss	temp,0
	bcf	GPIO,0
	btfsc	temp,0
	bsf	GPIO,0
	rrf	temp,f
	call	delay
	decfsz	count,f
	goto	Loop

Mike.
 
Both of those code snippets helped, thanks.

One question, and it might just be something I missed, the $+/-<Literal> jumps instructions? This would really be the same as setting multiple labels, just cleans up the code a bit, visually speaking. Or is there something else to it?

-Ken
 
When writing a program, it is best to use labels. Quite often it is hard to think up an intelligent label, so just use AA AB AC etc. The when the program is complete, you can replace the labels with $+4 $-6 etc.
But it is easier to see where the program is jumping to when you use labels during the design process.
It is also best to use labels as this allows you to add extra lines of code without having to change an instruction such as: goto $-15.
 
When writing a program, it is best to use labels. Quite often it is hard to think up an intelligent label, so just use AA AB AC etc. The when the program is complete, you can replace the labels with $+4 $-6 etc.
I can't see why you would replace the labels at all. If the program is complete, and you never edit it again, why bother? If you do go back to it ever again, relative jumps are a pain. If you want to obfuscate the code, keep it to yourself and only send out the hex code.

The only times that I have seen them used usefully is in macros where some assemblers can't handle jumps to labels, and in very short jumps of $-1, $, or $+1 where they just become shorthand for previous line, this line, and next line.
 
Status
Not open for further replies.

Latest threads

Back
Top