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.
I tried putting a delay in between the colorset calls and that did not do anything but paused the program in between. No matter what I do pic wants to jump to the last colorset defined as "set" and keeps running that while skipping over the rest of colorsets routines.
 
That's what I thought, IFDEF/ENDIF is of no use to you, nor are any assemble time instructions.

How about using a variable (GPR) to store a value, then check that value and branch to the different routines as required. If you need to you could even store the value of the variable in the data EEPROM and read it as the program starts so it's independent of the volatile memory.
 
That's what I thought, IFDEF/ENDIF is of no use to you, nor are any assemble time instructions.

How about using a variable (GPR) to store a value, then check that value and branch to the different routines as required. If you need to you could even store the value of the variable in the data EEPROM and read it as the program starts so it's independent of the volatile memory.

If you were to store it how do you place them in the bottom of the program subroutines (Red, Green, Blue) while allowing the main program to call them. That seems to be the issue.
To give you an example forget about c1, c2, c3 for a moment. When I straight out, put bianary numbers in RED, Green, Blue routine, and move it to iPORTA, there is no issue. Main program grabs it and runs with it.
Now if I set c1, c2, c3 to have 3 bianary numbers then place them in order in RED, Green, Blue subroutine, the program still takes it and main still grabs them and run with it.
The problem comes about when you change c1, c2, c3, several times in packetts and tell RED, Green, Blue Routine to take it. It seems it takes one set, locks it in, and main program only runs that one set over and over. I am open to suggestion and I believe youa re onto something interesting.
 
Put the values in a table, and use the variable as the index to the table - or create an IF/THEN/ELSE/ENDIF construct.

Second suggestion first. I need to play with it a bit and read the protocal for if.then.else.endif. This is less intrussive and complicated if it works.
First suggestion: I believe to make that work you need to call these values from a table directly from the main program and skip R<G<B routines. Given there are 24 frams, 24 sections calls in the main program, this adds additional lines in the main program making it even longer. I have almost used up allowed code lines and this might push it over the page limit. (unless I change to pic16f88)
 
Nigel is this what you were thinking?
Header
Color set Color1
call Colortest
Color set Color2
call Colortest
....
Color set Color12
call Colortest

;--------------------
Colortest
if color==Color1
movlw b'00010000'
movwf C1
movlw b'01000000'
movwf C2
movlw b'10000000'
movwf C3
call mainprog
;----------------------------
if Color==Color11
............
call mainprg
else Color==Color12
...........
call mainprog
endif
-----------------
Mainprog
..............
call Red
.............
call Green
.............
call Blue
Return
;--------------------
Red
movlw C1
movwf iPORTA
return
;--------------------
Green
movlw C2
movwf iPORTA
return
;--------------------
Blue
movlw C3
movwf iPORTA
return
 
I tried if,else,endif method. It sets c1 and ignores c2, and c3. It also skipped over all the other if conditions. (or ignored them)
Considering the main program being complex and very time consumer, the pic could not possibly zip thru the main program so fast that it wont read intermiate conditional codes. This is weird. I can't figure it out. Something so simple.
 
I believe I found the issue. Now I need help finding the cure.
Please consider the following code:

Colorset1
C1 set b'00010000'
C2 set b'11010000'
C3 set b'00010000'
call MainProg
return
;----------------------------------
Colorset2
C1 set b'00010000'
C2 set b'01000000'
C3 set b'10000000'
call MainProg
return

There is something about "set" function, and/or "return" function and/or name label that pic does not like. It could be spacing, indent, or some other reasons as well. In this case it grabs the bottom set (last set of data) and overwrite the first set. As long as these two "call" routines are followed by each other the second routine takes over as if it did not see the first set as a subroutine and only a few lines of codes skipping to final set of bianary numbers and sends those out only!
 
Of course it does. The 3 variables C1,C2,C3 can only contain one value each.

So if you fill the 3 variables in one call, then fill them again in the second call, they will be overwritten. Really, what did you expect it was going to do?

I think you should start with the basics, a neat flowchart type description of what the program actually does. Then people can help advise with the best code to use for each of the blocks in your flowchart. The flowchart does not need to be a picture, you can do it as text if you like just make it have clearly defined blocks where each block does its own task.
 
Of course it does. The 3 variables C1,C2,C3 can only contain one value each.

So if you fill the 3 variables in one call, then fill them again in the second call, they will be overwritten. Really, what did you expect it was going to do?

I think you should start with the basics, a neat flowchart type description of what the program actually does. Then people can help advise with the best code to use for each of the blocks in your flowchart. The flowchart does not need to be a picture, you can do it as text if you like just make it have clearly defined blocks where each block does its own task.

I explained how the program works only 6 times. One reading the thread carefully would have a better understanding. That said below is a simplified flowchart for any suggestions:
Simplified Flowchart:
1- Set Values for Color1, Color2, Color3 (variables used by the main program to set colors).
2- Main Program is called. Main sets the bits for PORTB, and places variables above in PORTA one at a time, and does puedo-pwm (modulates). PortB sets the anodes, while PORTA sets R,G,B (Cathodes) in the hardware.
3- Main calls an OUTPUT routine where Bytes in PORTA, and PORTB are pushed out. This completes one entire cycle.
4- Set new values for Color1, Color2, Color3
5- Call Main Program
6- Main calls the Output routine
7- Repeat this process for new values of Color1, Color2, Color3 (25 times)
 
I agree with Mr RB
If you're going to change the direction of the program while it is running, then you need some outside input like some push button switches. You continuosly test for a button press on one of the buttons and if pressed then go to that part of the program or adjust the variables at that point. It continues there till another button is pressed
 
To Clarify what has been tried and what the outcome was please read below:
A) Using "Set" directive once to create values for Color1, Color2, and Color3 worked perfectly. Once you "Set" these values again is when the issue arises and new data overwrites the previous without completing the cycle of "Main" program and "Output" calls.
B) Using movlw and movwf to set Color1, Color2, and Color3 results in undesirble output. One color is repeated while the third color is ignored.
C) Using if,then, else, endif: the results were similar to B)
 
I agree with Mr RB
If you're going to change the direction of the program while it is running, then you need some outside input like some push button switches. You continuosly test for a button press on one of the buttons and if pressed then go to that part of the program or adjust the variables at that point. It continues there till another button is pressed

Aaron
All the I/O on the PIC are used and there are no pins available for SW. The issue again is you are giving PIC new values for these variables with a press of SW. If we are overwriting the data by setting new values in variables, then the PIC will overwrite your attempt to assign new values with press of SW. Same issue...
 
To Clarify what has been tried and what the outcome was please read below:
A) Using "Set" directive once to create values for Color1, Color2, and Color3 worked perfectly. Once you "Set" these values again is when the issue arises and new data overwrites the previous without completing the cycle of "Main" program and "Output" calls.

As I've said all along, using assembler directives (such as 'set') requires you to reassemble the code, and reprogram the PIC from scratch - NOT what you want.

B) Using movlw and movwf to set Color1, Color2, and Color3 results in undesirble output. One color is repeated while the third color is ignored.
C) Using if,then, else, endif: the results were similar to B)

That's because you're not using them correctly - I can only imagine you're confused by using 'set' instead of assembler instructions?.

Like everyone else, I'm still confused as to what you're trying to do?, it's still completely unclear.
 
Aaron
All the I/O on the PIC are used and there are no pins available for SW. The issue again is you are giving PIC new values for these variables with a press of SW. If we are overwriting the data by setting new values in variables, then the PIC will overwrite your attempt to assign new values with press of SW. Same issue...

No, the 'issue' is that you're doing it wrong.
 
What if we create 3 new variables. Call them C1, C2, C3. I "set" the variables.
Then initialized Color1, Color2, Color3 (working variable), and declared them. Used movlw and movwf to assign values from C1 to Color1, C2, to COlor2, and C3 to Color3 and call the main program!
Then use lets say C4, C5, C6, "Set" them. Then again use movlw and movwf to transfer then data to Color1, Color2, Color3 and call main....and so on. Does anyone think that might work?
Is it possible in a "set" directive, one you set the values you can not change them during the program? If so separating working variable from "set" values might help the situation. Your thoughts....
 
Nigel are you suggesting that I am using the wrong syntax or the placement of change bits are off? What am I doing wrong?
 
What if we create 3 new variables. Call them C1, C2, C3. I "set" the variables.
Then initialized Color1, Color2, Color3 (working variable), and declared them. Used movlw and movwf to assign values from C1 to Color1, C2, to COlor2, and C3 to Color3 and call the main program!
Then use lets say C4, C5, C6, "Set" them. Then again use movlw and movwf to transfer then data to Color1, Color2, Color3 and call main....and so on. Does anyone think that might work?
Is it possible in a "set" directive, one you set the values you can not change them during the program? If so separating working variable from "set" values might help the situation. Your thoughts....

As I've said repeatedly - SET is an assembler directive, NOT an instruction - it has no effect other than at assembler time.

I would suggest you remove all uses of 'set' and start writing code instead :D
 
That's what I thought, IFDEF/ENDIF is of no use to you, nor are any assemble time instructions.

How about using a variable (GPR) to store a value, then check that value and branch to the different routines as required. If you need to you could even store the value of the variable in the data EEPROM and read it as the program starts so it's independent of the volatile memory.

Can the OP use the (GPR).... I'm just beginning to learning the flow of C and have learned about void* malloc() .malloc() and realloc() .realloc() &get or in assembly (GPR) it seems this would work if you had enough storage on the PROM.

I read something on Dynamic Arrays in Assembly but, I don't know about PIC's and storage limit's. I think it's 256 from what I've read, can't remember still learning. (Edit: I read the specs 224)

In the summer I plan to get setup and do some beginner programming, I hope it's not going to be this difficult:rolleyes:

Edit:Edit: Never mind, I just read this thread 3x3x3 cube
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top