Simple Assembly Language Quesiton
tom90
Posts: 55
How do I read information from a pin in Assembly Language?
I am trying to send out a simple square wave on one pin, and read it with another pin.
After the second pin reads in the info, I want to send it to a third pin to output it again.
Just a simple exercise to try and better learn assembler.
I got the square wave to work just fine, but I cant get the second pin to read in the info.
I tried using something like
andn dira, pin 'sets the pin to an input
mov ina, pin 'trying to read the info coming in on the pin (didn't work)
How do I read in this information so that i can pass it to another pin to be output again?
I would assume I have to store it in a variable somehow...if this is the case, can I read
it in and store it in a variable all in one step?
Thanks
Tom
I am trying to send out a simple square wave on one pin, and read it with another pin.
After the second pin reads in the info, I want to send it to a third pin to output it again.
Just a simple exercise to try and better learn assembler.
I got the square wave to work just fine, but I cant get the second pin to read in the info.
I tried using something like
andn dira, pin 'sets the pin to an input
mov ina, pin 'trying to read the info coming in on the pin (didn't work)
How do I read in this information so that i can pass it to another pin to be output again?
I would assume I have to store it in a variable somehow...if this is the case, can I read
it in and store it in a variable all in one step?
Thanks
Tom
Comments
MOV temp,INA
and then test one or more bits in temp or you can do:
TEST pin,INA WC
This will use the bitmask "pin" to test the INA register and set the C flag if the result is non-zero.
mov mask, #1
shl mask, pin
test mask, ina wz
if the pin is low, the zero flag will be set. You will of course have to define a long for "mask".·
I'm sure there's probably an easier way.· I guess I assumed "pin" had the pin number rather than a mask.· The first two instructions create a mask from the pin number.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Post Edited (Ken Peterson) : 10/16/2007 3:23:15 PM GMT
Second, These flags are very new to me, so please bare with me.
When I set these flags, How do i use the information on the next cog when i want to output that signal again?
I wanted this operation to be in a separate cog as the one that reads in the information. How will this work if I
am reading in 8 bits, for example
test mask, ina WC
test mask, ina WC
test mask, ina WC
test mask, ina WC
test mask, ina WC
test mask, ina WC
test mask, ina WC
test mask, ina WC
jmp #:loop
can I alter the C flag eight times in a row and still be able to read it properly in the other cog? How do I read it in the other cog?
if_nc andn outa, pin
if_c mov outa, pin
Would this be correct?
Thanks for all the help
Tom
The Z and C Flags are part of the CPU in a COG. They are needed to do conditional execution of following instructions.
Another COG has a totally independent CPU with its own flags. You cannot read the flags of another Cog.
This Flags exists only 1 time in every Cog, if you do 8 times 'test mask,ina WC' then the C-flag is overwritten every time.
If one Cog have to read a value from another Cog you normally go over the Hub-RAM. One Cog writes the value to the HubRAM with wrbyte (/word/long), and the other Cog can read it from the HubRAM with rdbyte(/word/long).
But especially for Pins this is not necessary, because all Cogs has parallel access to the pins.
So for your test program, you can read a pin in one Cog and set a second pin according to the state of the fist pin. Then a second Cog can read this second pin and set a third pin according to the second. A good Assembly instruction to set 1 ore more pins according a state of a flag is MUXC and MUXZ:
test firstpinmask,ina WZ 'Test the pin and set the Z flag to its state (inversed: Z is 1 if pin=0, and 0 if pin=1)
muxnz outa,secondpinmask 'Set the second pin to the invers state of Z flag
Andy
http://forums.parallax.com/forums/default.aspx?f=25&m=187621
MUXNZ did the trick
Thanks for all the help,
Tom
I think it's something like this:
test mask1, ina wz
muxnz outa, mask2
right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Post Edited (Ken Peterson) : 10/19/2007 11:10:12 PM GMT
He doesn't need flags in the first place.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
I am also posting my code for those who wanted to see it.
Thanks to all who have helped me so far.
Tom
Any Ideas?
Thanks again,
Tom
"time" is allocated in COG "conrolbyte".
COG "reading" accessses an arbitrary cell allocated where "time" would be in the other COG.
A workaround will be to make the main program set a time stamp both COGS can sync to. BE careful to not set this time stamp before both COGs are working...
If I set the variables "time" and "delay" in the main program, how do I pass those variables to the the waitcnt statements in the two cogs running assembly?
I think you and mike are talking about the same thing, but I'm not quite getting it to work.
Thanks
Post Edited (Mike Green) : 10/30/2007 3:21:43 PM GMT
That probably would have taken me years to figure out.
Thanks for all your help!
Tom