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.

Indirect addressing issue with 16f84a

Status
Not open for further replies.

MWostal

New Member
I know its an old PIC, I know there are better ones out there but its what I have. I have been searching the Microchips documentations, the PIClist files and all over the internet for this issue but have found no answer so I ask it here.

My program uses indirect addressing to access different tables (YES, its another damned LED program but we all have to start somewhere) :) The trouble is that although the FSR shows the correct addresses when stepping through the application the W register never loads with the data stored at that address. My understanding of the INDF implimentation is that I store an address in FSR and reading INDF will give me the data stored at the address pointed to by FSR. This is not happening.

** code snippit **
Loop1 movf Count,w ; Put current count into W
addwf CurPatt,w ; Update current position in sequence
movwf FSR ; Store this Indirect register
movf INDF,w
movwf PORTB
** end **

I am using MPLAB IDE and stepping through the program using MPLAB SIM

All examples I have found show this as proper but still it fails to work. Does the 16F84a INDF not function correctly? Even the old 6809e processor could do indirect addressing so what am I doing wrong?
 
In a Harvard architecture there are two separately addressable memory spaces. The FSR points to the register file, not the program space. The program counter points to the program space, not the register file. The register file contains data items which are eight bits wide. The program space contains words which are 14 bits wide.

Na'er the twain shall meet.

That is why tables are implemented with the "retlw" instruction.
 
Thank you Papabravo. At least that explains the data I was seeing in the W :) I have seen the RETLW instruction and some examples but it always struck me as a very sloppy and dangerous way to get data. One goof and the PC is now pointing to Andromeda instead of the next program line but if its all that is available I guess its what I have to use.
Thanks again for the speedy reply.
 
MWostal said:
Thank you Papabravo. At least that explains the data I was seeing in the W :) I have seen the RETLW instruction and some examples but it always struck me as a very sloppy and dangerous way to get data. One goof and the PC is now pointing to Andromeda instead of the next program line but if its all that is available I guess its what I have to use.
Thanks again for the speedy reply.

Check my PIC tutorials, the first ones do LED flashing in various ways, including from a data table.
 
Nigel,

I have seen your examples and tutorials and have found them an excellent source of information. As soon as Papabravo mentioned the RETLW I thought of them as where to go :) And now I also understand why you didnt use the Indirect method in them, you cant! Again thanks for the information and hope I didn't irritate anyone too much.
 
help about using Tables

I’m a beginner. I have a question about TABLES.
When I use ‘values’ (=0x35) it returns values. But when I Use ‘variables’ (=PICK1), it returns address of the variable.

w = 1
.
Retlw 0x35
Retlw 0x36
.
w = 0x36 OK
----------------
PICK1 equ 0x20
.
move some value to PICK1
.
w = 1
.
retlw PICK0
retlw PICK1
.
w = 0x20 ????

Thank U all for helping others..
 
I suggest you read the datasheets to see what the instructions do? - RETLW is RETurn Literal in W - it returns the following fixed number in the W register, you gave it the value 0x20 and it returned it, exactly as expected. You can't use a variable, it's a literal number only.
 
MWostal said:
Loop1 movf Count,w ; Put current count into W
addwf CurPatt,w ; Update current position in sequence
movwf FSR ; Store this Indirect register
movf INDF,w
movwf PORTB

MWostal:
Does CurPatt need to be modified or saved? If Count and CurPatt are not being updated externally, then FSR will keep pointing to the same location. Maybe you meant to do this:
.
ADDWF CURPATT, F
MOVF CURPATT, W
.
.
.

Provide some more view of the code because the snippet is not looping from where we are viewing.
 
donniedj:
As soon as it was pointed out that indirect addressing was for RAM and not program accessing I changed the program (using Nigels excellent tutorial btw) to the retlw style and my program runs perfectly now.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top