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.

Exiting a subroutine without using return?

Status
Not open for further replies.

davepusey

Member
I am writing a program for the PIC16F84A. What i need to do is at the end of my subroutine return to a specific place in the code instead of the line after that which called the subroutine. Can i do this using a GOTO instruction instead of the RETURN instruction? If not, then how?

Thanks in advance.
 
davepusey said:
I am writing a program for the PIC16F84A. What i need to do is at the end of my subroutine return to a specific place in the code instead of the line after that which called the subroutine. Can i do this using a GOTO instruction instead of the RETURN instruction? If not, then how?

Thanks in advance.

If you're calling a subroutine (using call) the return address is pushed onto the stack, so if you don't execute a return (which pops the return address off the stack), the stack will soon overflow.

If you want to do this, don't use a subroutine, and don't use 'call', simply use 'goto' to call the routine, and another 'goto' to return where you want.
 
Right ok that's fine.

One other thing, im using the BTFSC instruction but an not sure if i have to write the bit numbers as 0,1,2,3,4,5,6,7 or 1,2,4,8,16,32,64,128. Which is it please?
 
davepusey said:
falleafd said:
Look at the instruction set in the datasheet of your PIC.

Yes I would like to but when i goto **broken link removed** and click on the "PIC16F84A Datasheet **broken link removed**" link all i get is a 404 File Not Found error.

Look at the MPASM helpfile (installed along with MPLAB), it tells you most things you need to know.
 
that's strange. I'll upload this to my site for ya...hang on.

here you go....

**broken link removed**

Will be uploaded in a few minutes.
 
Check the Datasheet. It think memory starts @ 0Ch. yes just doubled checked.

;)

Code:
cblock    0Ch

var1
var2

endc

That'll do it.
 
bsodmike said:
Check the Datasheet. It think memory starts @ 0Ch. yes just doubled checked.

;)

Code:
cblock    0Ch

var1
var2

endc

That'll do it.

Oh. I was just gonna do

RUNSEQ1 EQU 0Ch
RUNSEQ2 EQU 0Dh

Also how do i do a "if RUNSEQ1=<decimalnumber> then do the next line, overwise skip it" statement?

Sorry for all these odd questions but this is my first ever PIC program.
 
davepusey said:
bsodmike said:
Check the Datasheet. It think memory starts @ 0Ch. yes just doubled checked.

;)

Code:
cblock    0Ch

var1
var2

endc

That'll do it.

Oh. I was just gonna do

RUNSEQ1 EQU 0Ch
RUNSEQ2 EQU 0Dh

That's perfectly OK, but using cblock/endc just makes it simpler (and shorter to type).

Also how do i do a "if RUNSEQ1=<decimalnumber> then do the next line, overwise skip it" statement?

You don't in assembler, that's a high level language command. In assembler you need to compare two values, either by subtraction or XOR, then check the status flag values. If you consult the PICList there is a complete section on various methods of doing this.
 
Nigel Goodwin said:
davepusey said:
Also how do i do a "if RUNSEQ1=<decimalnumber> then do the next line, overwise skip it" statement?

You don't in assembler, that's a high level language command. In assembler you need to compare two values, either by subtraction or XOR, then check the status flag values. If you consult the PICList there is a complete section on various methods of doing this.

I knew that :D. I just writing it like pseudo code.

Here's what i want to do... perhaps you can help me convert this to assembler...

If RUNSEQ1 == .17 then C=0
If RUNSEQ1 == .136 then C=1
 
Code:
     MOVLW    .17
     XORWF    RUNSEQ1, W
     BTFSC    STATUS, Z
     CLRF     C

This loads W (the accumulator) with 17 decimal. and does a exclusive or of this value with the value in runseq1. If both are identical then the result of this operation will be 0. So we check the Z(ero) flag in status register and if set, we clear C...

Do something similar for the second compare
 
Exo said:
Code:
     MOVLW    .17
     XORWF    RUNSEQ1, W
     BTFSC    STATUS, Z
     CLRF     C

This loads W (the accumulator) with 17 decimal. and does a exclusive or of this value with the value in runseq1. If both are identical then the result of this operation will be 0. So we check the Z(ero) flag in status register and if set, we clear C...

Do something similar for the second compare

Getting an error...

Symbol not previously defined (Z)

Also how do i convert my code to a .hex file?
 
Nigel Goodwin said:
davepusey said:
How do i send the contents of RUNSEQ to PORTB ?

Code:
movf     RUNSEQ, w
movwf   PORTB

Ah. I have something slightly different from MOVF and it wasnt working. Thanks for that.

Program is running lovely in simulator.
 
Now i need to superimpose RUNSEQ and RUNSEQ2 storing result in W. By superimpose i mean like this...

Code:
RUNSEQ        10001000
RUNSEQ2       01000100

Result in W   11001100

I thought i could use an OR but i cant seem to figure it out. Your help would be helpful (yet again)!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top