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.

Need PIC Assembly Help: Changing variable sets to be placed in subroutine "CALL"...

Status
Not open for further replies.

Chipwizard

New Member
Hello
I am in the middle of a pic programming project and need help with what appears to be syntax issue:
The program has two sections: Main Body, and set of subroutine calls retrieving values from 3 individual subroutines. Main body calls these 3 subroutines, subroutine places an 8-bit value in PORT-A and returns to main program to do bunch of stuff. I would like to be able to change each 8-bit value in the begining of the program, set three 8-bit values in 3 variables in the 3 subroutines, call "main" program to do its thing, come back and change (set) new values for the variables, place the new values in subroutine call, call "main program" to do its thing and so on...

I tried "set" function in the begining then called main. The results are that it grabs the last set of 3 variables and keeps running it and ignores the rest of previous "set" subroutines. Any suggestions will be greatly appreciated.

Thanks,
Rom
 
Correction: I am not returning PORTA but rather a variable representing PORTA which in turn places value in PORTA at a Output call.
Here is some snippets I have so far for clarification:
Sequence
Call Colorset1
Call Colorset2
Call Colorset3
Goto Sequence
.....
Colorset1
C1 set b'00010000'
C2 set b'01000000'
C3 set b'10000000'
call Main-prog
Return
Colorset2
C1 set b'01000000'
C2 set b'11000000'
C3 set b'01010000'
call Main-prog
Return
......
Main-prog
do bunch of stuff
call Red
do bunch of stuff
call Green
do bunch of stuff
call Blue
.......
Return
.......
Red
movlw C1
movwf iPORTA
Return
........
Green
movlw C2
movwf iPORTA
Return
.......
Blue
movlw C3
movwf iPORTA
Return
......
end
 
Try it like this;

Code:
Colorset1 

movlw b'00010000'
movwf	c1

movlw b'01000000'
movwf	C2 

movlw b'10000000'
movwf	C3
 
Rom
I'm definetly no expert, far from it, and I'm not even sure I understand what you mean by
I would like to be able to change each 8-bit value in the begining of the program, set three 8-bit values in 3 variables in the 3 subroutines
, but I right away thought it might be a place in the header for an IFDEF statement. If the values will be reaccuring. That way they could be easily changed at program time.
Aaron
 
Hi HOUSE
I tired that trick as well. What the PIC does is to grab the first color (C1) and ignores (sets to zero) C2 and C3. There is something about setting the value in the call routine that can not be changed for some reason once set! Any other ideas?
Regards,
Rom
 
Hi AGCB
To clarify take a look at colorset1 and colorset2. That is what I mean by changing the 8-bit values in C1, C2, and C3. The top part was not part of the original code. It was just main-prog and subroutine calls to Red, Green, and Blue with actual biaary numbers set in subroutines (Red, Green, Blue).
Please elaborate on your IFDEF idea with a simple snippet so that I understand your idea.

Thanks,
Rom
 
Hi Nigel
Please take a look at the snippet I posted. I am trying to put values in c1, c2, c3. Then have subroutines Red, Green, Blue pick up these values, in turn place them in iPORTA, return the value to the main program as they are called by main program, use these values to do lots of stuff in the main program. Once this is done, I want to give c1, c2, and c3 new values, place them in Red, Green, Blue subroutines, run the main program to grab these new values and do the same stuff with the new values.
 
As-is the way the code is written in the snippet, PIC ignores colorset1, and goes directly to last colorset and just keeps repeating it.
 
Your problem could be to do with the 'bunch of stuff' you mention, what does it do / be supposed to do?

House:
The main program works just fine. As I mentioned above in Red, Green, and Blue routines, instead of c1, c2, c3, I originally had b'0001000', b'01000000', b'10000000'. Everything worked perfectly. But I wanted to be able to do this without writing the main-prog over and over, by just changing these bytes in subroutines Red, Green, Blue and repeat the same code in the main-prog. Each pass puts a new value in Red, Green, Blue so main-prog can call them. (i.e. "call Red", call Green, call Blue)
 
Last edited:
I wonder if a DELAY routine is in order between each colorset calls allowing the pic to settle before going to the next colorset subroutine. That I have not tried.
 
Please elaborate on your IFDEF idea with a simple snippet so that I understand your idea.

Something like this.

;header

;#define Color1 ;this line commented out
#define Color2 ;This line tells program to use Color2 values



IFDEF Color1
C1 equ b'00010000'
C2 equ b'01000000'
C3 equ b'10000000'
endif


IFDEF Color2
C1 equ b'01000000'
C2 equ b'11000000'
C3 equ b'01010000'
endif


;Each time the registers C1,C2,C3 are used in the program, the values
; of Color2 will be used. All you have to change is the semi-colon

Aaron
 
Thank you again Aaron. So that I understand your concept:
"define" is my declaration (i dont need to declare it again in cblock?
Do I need to produce a new variable to place desired color to be tested in it(i.e. color1, color2,....) before it goes to conditional test?
Another words what am I testing to be equal to color1, color2, and so on?
I appreciate your help.
 
Something like this.

;header

;#define Color1 ;this line commented out
#define Color2 ;This line tells program to use Color2 values



IFDEF Color1
C1 equ b'00010000'
C2 equ b'01000000'
C3 equ b'10000000'
endif


IFDEF Color2
C1 equ b'01000000'
C2 equ b'11000000'
C3 equ b'01010000'
endif


;Each time the registers C1,C2,C3 are used in the program, the values
; of Color2 will be used. All you have to change is the semi-colon

Aaron

So I need the semicolon for the first color and the other defines don't need a semicolon? (11 other ifdefine's if I am doing this 12 times)
 
Thank you again Aaron. So that I understand your concept:
"define" is my declaration (i dont need to declare it again in cblock?
Do I need to produce a new variable to place desired color to be tested in it(i.e. color1, color2,....) before it goes to conditional test?
Another words what am I testing to be equal to color1, color2, and so on?
I appreciate your help.

The IFDEF/ENDIF constructs are assemble time instructions - is that what you want?, just a way to re-assemble the program and reprogram the PIC from scratch each time?.
 
The IFDEF/ENDIF constructs are assemble time instructions - is that what you want?, just a way to re-assemble the program and reprogram the PIC from scratch each time?.

Nigel I am not clear what you are asking me. I do not mind for the program start all over everytime I choose a new color set for c1, c2, c3. My intention is to give it the condition, select color set, and run the main program. If it starts all over then I can live with that. The main program does not store any data in memory, nor uses a table call. Nor I am warried about PCL. As long as after each condition, I can run the main program subroutine, all the values will be set in there as what I am doing and pushed out to output. I hope I am not missing anything...
 
Last edited:
Nigel I am not clear what you are asking me. I do not mind for the program start all over everytime I choose a new color set for c1, c2, c3. My intention is to give it the condition, select color set, and run the main program. If it starts all over then I can live with that. The main program does not store any data in memory, nor uses a table call. Nor I am warried about PCL. As long as after each condition, I can run the main program subroutine, all the values will be set in there as what I am doing and pushed out to output. I hope I am not missing anything...

This is where the confusion arises - nowhere in this quote do you mention removing the PIC from your circuit, connecting it to your programmer, and running MPLAB to re-assemble the changed program. Then re-write to the PIC, and re-fit the PIC back in your circuit. (I know it can be done using ICSP, but this makes it clearer I thought?).

It's not a matter or restarting the program, it's a matter of reassembling the code and re-writing the PIC.

If you want to do it without doing that, then IFDEF isn't going to help you.
 
No I do not want to take the chip out. Nor I do not want to reprogram it after one set of colors. That defeats the purpose. I want to be able to say c1= b'00010000', c2=another bianary, c3=another bianary.
My main program call 3 subroutines called RED, Green, Blue. In these subroutines, the bianary numbers are placed in perspective RED, GREEN, AND BLUE subroutine calls. Then these values are returned back to main program (c1, c2, c3) to do psuedo-pmw, multiplex, and call output subroutine which puts values of porta and portb in their place to be displayed. I thought the snippet I put up was straight forward. May be I am not making it clear as how the the entire program functions. I hope this helped...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top