Need a way in PASM to set a port high or low - not toggle it....
Chris_D
Posts: 305
Hi guys,
I am stuck in assembler.· All I need to really do is set a specific output pin to either High or Low depending on a condition.· Currently I use the following...
Xor·· outa, A1D_pinmask
This statement exists in two places and depending on wheter I want it high or low, I direct flow to do this.· The following is a part of the actual program...
Determine_Dir·········· cmps··· A1P_AbsPos,A1P_TarPos wc, wz·· 'compare target to current position
······· if_z··········· jmp···· #Top··························· 'target equals current, no change required
······· if_c··········· jmp···· #SetFwd························ 'Current is less than target position - move fwd
SetRev················· mov···· A1D_Direction, #0·············· 'Set direction to reverse
······················· cmps··· A1D_Direction, A1D_Prev_Dir wz· 'Check which direction to set pin
······· if_nz·········· xor···· outa,A1D_pinmask··············· 'If not equal, change state
······················· mov···· A1P_delta,DeltaMinus··········· 'Set Delta value to -1 so position incrementing is correct
······················· mov···· A1D_Prev_Dir,A1D_Direction····· 'Update prev_dir flag
······················· jmp···· #Top··························· 'jump to top of loop
SetFwd················· mov···· A1D_Direction, #1·············· 'Set direction to fwd
······················· cmps··· A1D_Direction, A1D_Prev_Dir wz· 'Check which direction to set pin
······· if_nz·········· xor···· outa,A1D_pinmask··············· 'If not equal, change state
······················· mov···· A1P_delta,DeltaPlus············ 'Set Delta value to -1 so position incrementing is correct
······················· mov···· A1D_Prev_Dir,A1D_Direction····· 'Update prev_dir flag
······················· jmp···· #Top··························· 'jump to top of loop
While this works most of the time, it is very easy to get this out of Synch and when I want forward, I get reverse aand of course the opposite can be true to.· But, as you can see, it is actually toggling the port as opposed to setting it to a specific state.·
I started looking into the MUXC instruction, but can't figure out how I would actually use it.
Can someone shed a bit of light on how to set a port specifically to either on or off?
Thanks
Chris
·
I am stuck in assembler.· All I need to really do is set a specific output pin to either High or Low depending on a condition.· Currently I use the following...
Xor·· outa, A1D_pinmask
This statement exists in two places and depending on wheter I want it high or low, I direct flow to do this.· The following is a part of the actual program...
Determine_Dir·········· cmps··· A1P_AbsPos,A1P_TarPos wc, wz·· 'compare target to current position
······· if_z··········· jmp···· #Top··························· 'target equals current, no change required
······· if_c··········· jmp···· #SetFwd························ 'Current is less than target position - move fwd
SetRev················· mov···· A1D_Direction, #0·············· 'Set direction to reverse
······················· cmps··· A1D_Direction, A1D_Prev_Dir wz· 'Check which direction to set pin
······· if_nz·········· xor···· outa,A1D_pinmask··············· 'If not equal, change state
······················· mov···· A1P_delta,DeltaMinus··········· 'Set Delta value to -1 so position incrementing is correct
······················· mov···· A1D_Prev_Dir,A1D_Direction····· 'Update prev_dir flag
······················· jmp···· #Top··························· 'jump to top of loop
SetFwd················· mov···· A1D_Direction, #1·············· 'Set direction to fwd
······················· cmps··· A1D_Direction, A1D_Prev_Dir wz· 'Check which direction to set pin
······· if_nz·········· xor···· outa,A1D_pinmask··············· 'If not equal, change state
······················· mov···· A1P_delta,DeltaPlus············ 'Set Delta value to -1 so position incrementing is correct
······················· mov···· A1D_Prev_Dir,A1D_Direction····· 'Update prev_dir flag
······················· jmp···· #Top··························· 'jump to top of loop
While this works most of the time, it is very easy to get this out of Synch and when I want forward, I get reverse aand of course the opposite can be true to.· But, as you can see, it is actually toggling the port as opposed to setting it to a specific state.·
I started looking into the MUXC instruction, but can't figure out how I would actually use it.
Can someone shed a bit of light on how to set a port specifically to either on or off?
Thanks
Chris
·
Comments
To set a bit high, you would OR it with a mask of the bit in question, and to set it low you would ANDN it with the mask.
Cheers,
Peter (pjv)
PS See this link, Step 2: · Assembly, step by step
Post Edited (pjv) : 9/20/2009 4:16:14 PM GMT
thanks much for the information, I will give it a try this afternoon.· I did try to go to that link but it didn't work :-(
Thanks
Chris
this sets the bit to the state of the Z-Flag. If you need to set it to the inverted state of the Z-Flag use: muxnz
Andy
The suggestions worked and I now am controlling the outputs much more reliably.
Chris