| Author |
Message |
|
|
Posted: Jul 09, 2012 - 10:41 PM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
Hello everybody, I am using aATtiny25 and have a problem to change a value of a symbol with the .SET assembler directive. It says in the manual that i can change the value at any time in the program code, but it dosen't, and when i assembler the code in the AVR studio4 it dosen’t give any errormessage either.
For example:
mov r16, r5
sbrc r16, 2
rjmp Skift
.SET P_long = 1
.SET P_kort = 2
rjmp Outskift
Skift:
.SET P_long = 2
.SET P_kort = 1
Outskift:
sbis pinb, P_long
rjmp long
sbis pinb, P_kort
rjmp kort
The purpose is to change the input-pins when bit 2 in r16 change status.
It is always the last .set who sets the value of the variables.
I would be greatful if i could have some help to solve this problem because I am stucked here.
/Rapnaza |
|
|
| |
|
|
|
|
|
Posted: Jul 09, 2012 - 11:03 PM |
|

Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia
|
|
| .SET is an assembly time assignment, not runtime. It works regardless of the program flow and just silently overwrites the previous assignment. Do not use it at all because 1) you do not understand how it works and 2) you do not need it to get your scenario working properly. |
_________________ Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
|
| |
|
|
|
|
|
Posted: Jul 09, 2012 - 11:10 PM |
|

Joined: Feb 12, 2005
Posts: 16312
Location: Wormshill, England
|
|
|
Rapnaza wrote:
Hello everybody, I am using aATtiny25 and have a problem to change a value of a symbol with the .SET assembler directive. It says in the manual that i can change the value at any time in the program code, but it dosen't, and when i assembler the code in the AVR studio4 it dosen’t give any errormessage either.
For example:
Code:
mov r16, r5
sbrc r16, 2
rjmp Skift
.SET P_long = 1
.SET P_kort = 2
rjmp Outskift
Skift:
.SET P_long = 2
.SET P_kort = 1
Outskift:
sbis pinb, P_long
rjmp long
sbis pinb, P_kort
rjmp kort
The purpose is to change the input-pins when bit 2 in r16 change status.
It is always the last .set who sets the value of the variables.
I would be greatful if i could have some help to solve this problem because I am stucked here.
/Rapnaza
The Assembler just assembles. It does not follow your program flow.
So P_long is always going to be 2 in your sbis statement.
If you want different behaviour, you need to have :
Code:
rjmp Skift
Outskift:
sbis pinb, 1
rjmp long
sbis pinb, 2
rjmp kort
Skift:
sbis pinb, 2
rjmp long
sbis pinb, 1
rjmp kort
If you want your skips to change at run time, you must put the value of PINB into a register and test a mask.
David. |
|
|
| |
|
|
|
|
|
Posted: Jul 09, 2012 - 11:19 PM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
| Okey, thanks for the answers. Is there another whay to change the variable value to achive my purpose to change the pins? |
|
|
| |
|
|
|
|
|
Posted: Jul 09, 2012 - 11:45 PM |
|


Joined: Nov 22, 2002
Posts: 12049
Location: Tangent, OR, USA
|
|
There are several ways. David's is the simplest and most direct.
To set a port pin, you can read the port, OR the desired pin mask with the port value, and write it back. To clear a port pin, read the port, AND the complement of the desired pin mask with the port value, and write it back.
On newer chips you can toggle a port pin in PORTx by writing to the PINx register.
Jim |
_________________ Jim Wagner
Oregon Research Electronics, Consulting Div.
Tangent, OR, USA
"The only thing standing between us and victory is defeat" P.G.Wodhouse in Wooster & Jeeves series
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 07:58 AM |
|

Joined: Feb 12, 2005
Posts: 16312
Location: Wormshill, England
|
|
|
Code:
rjmp Skift ;2
Outskift:
sbis pinb, 1 ;
rjmp long
sbis pinb, 2
rjmp kort
Skift:
sbis pinb, 2 ;2
rjmp long
sbis pinb, 1 ;1
rjmp kort ;2
Untested
Code:
Skift:
ldi r19, 0b00000110 ;1 flip test bits 1,2
rjmp any ;2
OutSkift:
ldi r19, 0b00000000 ; regular
any:
in r18, pinb ;1
eor r18, r19 ;1 change bits or not
sbrs r18, 1 ;2
rjmp long
sbrs r18, 2 ;1
rjmp kort ;2
Quite honestly, the boring first solution looks efficient, uses no registers.
There are many ways of doing this. e.g. mask and branch, use T bit, ...
In practice, saving a couple of cycles is seldom important. Clear bug-free code is far more important.
David. |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 09:05 AM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
Okey, thanks Jim and David again for your advice.
But clearly I havent described my problem properly. I have apparently entered the wrong expression to this topic, the purpose is to swap (sorry not change) the input pins in the beginning of the program code so I could use the swap function further down in the program, that is why I would like to change the value in the variable because then I dont have to add the extra code that David gave me as an example.
/Rapnaza |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 09:14 AM |
|

Joined: Feb 12, 2005
Posts: 16312
Location: Wormshill, England
|
|
If you want to map pins at run-time, you can use a look-up table or a set of masks or several other methods.
I am a believer in keeping regular human logic, and writing all your functions in these terms.
You only need to map your hardware layout when you read a port, and remember to write any results back to the mapped pins.
David. |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 10:33 AM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
Yes David, but it still reminds me of the .SET directive.
The .SET directive can be overridden by a later .SET in the program unlike and differ from the .EQU directive as it says in the manual.
I still don’t get it when can I use this .SET directiv then?
/Rapnaza |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 10:45 AM |
|


Joined: Jul 18, 2005
Posts: 62313
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| .set is something that happens on you PC while the program is being assembled. It has nothing to do with what happens inside the AVR when it is running. If you want variables that change at runtime then use one of the 32 machine registers or some location in SRAM . |
_________________
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 11:06 AM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
THANK YOU clawson, this calmed my curiosity and replied to my question.
Best Regards
/Rapnaza |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 11:41 AM |
|


Joined: Jul 18, 2005
Posts: 62313
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Well to be honest I didn't really say anything more than:
Quote:
.SET is an assembly time assignment, not runtime.
so you already had the answer in the first response. |
_________________
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 12:07 PM |
|

Joined: Jul 09, 2012
Posts: 6
|
|
Well it my be so, but after all discussion with Jim and David and you at the end repeated the first response but in a more understanding way in your latest post. I finaly understod how it should be. Thanks again and also a big THANKS to Jim and David who helpt me in this topic.
Best Regards
Rapnaza |
|
|
| |
|
|
|
|
|
Posted: Jul 10, 2012 - 03:55 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
MBedder wrote:
.SET is an assembly time assignment, not runtime. It works regardless of the program flow and just silently overwrites the previous assignment. Do not use it at all because 1) you do not understand how it works and 2) you do not need it to get your scenario working properly.
Perhaps you need to brush up on your Russian.  |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|