PIC Assembly problem: Transfer value from one variable to another

Thread Starter

MRKane

Joined May 4, 2018
3
Hello all,

Please excuse what's possibly one of the more stupid questions you'll come across but I'm a C# programmer by profession so PIC Assembly has been annoying if anything else.

So I decided to expand the PS2 to N64 adaptor project as described here (http://www.afermiano.com/), using a PIC16F688, and while the original author of the project has been very helpful he's had little time to assist a newbie with an old project. As part of my expansion of function in the code I had to change how buttons were handled, first clearing the value fields upon which they're set, and then setting them as was originally in the project. The problem here is that the N64 interrupt read will sometimes read the buttons as blank (which ruins drifts in Mario Kart 64!).

I concluded that it was probably best to copy values from one field to another at the end of the process, and have the interrupt read that :) thing is that I cannot figure out how to get that working! And it should be crazy simple!

So what I've been trying to do is something akin to this, copying the values assigned in N64_BYTE_1 into READ_N64_BYTE_1:

movlw N64_BYTE_1 ;move address of byte into W register
movwf FSR ;make FSR ‘point’ to the address of the byte
movfw INDF ;moe the contents of the pointed file (byte) into W
movwf READ_N64_BYTE_1 ;move the contents of W into our target field​

But I'm just not smart enough to figure it out, so finally concluded that it was time to ask for assistance, as I'm sure it's something stupidly simple that I'm just not grasping here, so all assistance welcome just please don't be too cryptic ;)

I can also provide a project of the current build as it stands if that would be of assistance.
 

jpanhalt

Joined Jan 18, 2008
11,087
Hi, Welcome to AAC.

Not sure of what is causing the error. Here are some common things to look for:
1) Be sure the TRISx register for your port is set to input for the pins you need to read.
2) Be sure comparators are turned off if on those pins (admittedly, I didn't read the datasheet carefully). Also be sure the pins are set to digital (i.e, disable analog inputs if on those pins, see:ANSEL).
3) Be sure you don't have a bank problem with your target registers. The code you posted would not have that problem, but maybe you are coming from somewhere that is not Bank 0. One way around that is to use the Common RAM instead of General Purpose RAM. In the datasheet they are upper bytes of user RAM that point to Bank 0. Be sure your context saving code for the interrupt saves and restores the bank from which it comes.
4) The instruction set for that chip does not include movfw per se, which is an older version of "movf,w". I stopped using movfw as I constantly got it confused with movwf. I think most assemblers are not bothered by that instruction and make the substitution automatically (i.e., movf,w for movfw). One advantage of movf is that you can use movf,f to check for zero.

You can post code here using tags like this [code=asm] <put code here>[/code]

John
 

Thread Starter

MRKane

Joined May 4, 2018
3
Thanks so much for that super-rapid reply! The project works fine pertaining to standard function, so I can be sure it's not a pin issue. I was using movf,w previously but changed it just in case that was the problem (I truly am trying things until I get it working with this project).

I think your comment about banks might just be the issue here as the project is brilliantly well coded and setup using quite an array, and odds down I've done something wrong (or omitted something) upstream.

I guess that's the problem with a well written programme - it can be really difficult to make it do something different sometimes.

I didn't expect a reply so quickly, and it could be a few days until I get the chance to test this, but thank you so much!
 

Thread Starter

MRKane

Joined May 4, 2018
3
Well as it turns out you were right on the money jpanhalt! I'd been switching banks upstream and forgotten to set it for that block of code. I guess it's just one of those things that you never see when your nose is right close to the code!

Thanks so much!!
 
Top