PIC18f indirect addressing

Thread Starter

RG23

Joined Dec 6, 2010
304
I want to shift one column data to another column from column 71 to column 72

When I press switch 1, I display only one column of data

When I press switch 2, it should shift the data to the next column

Please have a look at the two simple subroutines below

B1, B2, B3, B4 are the four pages I use to get 32 bit vertical data column

Ignore the SND_CMD and SND_DTA subroutines as they are just the LCD command and data subroutines for the location on display

I am displaying the data in column 71 correctly

I am not getting the shifted data in column 72 correctly

Rich (BB code):
//////column 71 is used here
//////SND_CMD is the command subroutine 
//////SND_DTA is the data subroutine 
 
label_diplay_column_data:
 
 
LFSR 1,h'100' 
movlw 0xFF
movwf INDF1
movf POSTINC1,0
movlw 0xFF
movwf INDF1
 
movf POSTINC1,0
movlw 0xFF
movwf INDF1
 
movf POSTINC1,0
movlw 0xFF
movwf INDF1
 
movlw 0xB1
movwf PORTD
call SND_CMD
 
movlw 0x17
movwf PORTD
call SND_CMD
 
movlw 0x01
movwf PORTD
call SND_CMD
movf POSTDEC1,0
movf INDF1,0
movwf PORTD
call SND_DTA
 
movlw 0xB2
movwf PORTD
call SND_CMD
 
movlw 0x17
movwf PORTD
call SND_CMD
 
movlw 0x01
movwf PORTD
call SND_CMD
movf POSTDEC1,0
movf INDF1,0
 
movwf PORTD
call SND_DTA
 
movlw 0xB3
movwf PORTD
call SND_CMD
 
movlw 0x17
movwf PORTD
call SND_CMD
 
movlw 0x01
movwf PORTD
call SND_CMD
movf POSTDEC1,0
movf INDF1,0
 
movwf PORTD
call SND_DTA
 
movlw 0xB4
movwf PORTD
call SND_CMD
 
movlw 0x17
movwf PORTD
call SND_CMD
 
movlw 0x01
movwf PORTD
call SND_CMD
 
movf INDF1,0
 
movwf PORTD
call SND_DTA
 
return
 
Last edited:

Thread Starter

RG23

Joined Dec 6, 2010
304
Rich (BB code):
label_display_shifted_datacolumn:
         
          movlw  0xB1
          movwf  PORTD
          call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x01
         movwf  PORTD
         call   SND_CMD
         movlw   0x00
         movwf  PORTD
         call   SND_DTA
 
         movlw  0xB2
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x00
         movwf  PORTD
         call   SND_CMD
         movlw  0x01
         movwf  PORTD
         call   SND_CMD
         movlw   0x00
         movwf  PORTD
         call   SND_DTA
         movlw  0xB3
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x01
         movwf  PORTD
         call   SND_CMD
         movlw   0x00
         movwf  PORTD
         call   SND_DTA
         movlw  0xB4
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x01
         movwf  PORTD
         call   SND_CMD
         movlw   0x00
         movwf  PORTD
         call   SND_DTA

         movlw  0xB1
          movwf  PORTD
          call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x02
         movwf  PORTD
         call   SND_CMD
         
         movf   INDF1,0
         movwf  PORTD
         call   SND_DTA
         movlw  0xB2
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x02
         movwf  PORTD
         call   SND_CMD
         movf   POSTINC1,0
         movf   INDF1,0
         movwf  PORTD
         call   SND_DTA
         movlw  0xB3
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x02
         movwf  PORTD
         call   SND_CMD
         movf   POSTINC1,0
         movf   INDF1,0
         movwf  PORTD
         call   SND_DTA
         movlw  0xB4
         movwf  PORTD
         call   SND_CMD
        
         movlw  0x17
         movwf  PORTD
         call   SND_CMD
         movlw  0x02
         movwf  PORTD
         call   SND_CMD
         movf   POSTINC1,0
         movf   INDF1,0
         movwf  PORTD
         call   SND_DTA
         return
 

Thread Starter

RG23

Joined Dec 6, 2010
304
Using Pickit2 debugger I found that when I press switch1

the data in locations 100, 101, 102, 103 are all 0xFF

when I press switch2 , the data in those locations are not 0xFF

I wonder why is it so as I haven;t changed anything related to the data in those locations.

If anyone has an idea please let me know

Thanks
 

JohnInTX

Joined Jun 26, 2012
4,787
Rich (BB code):
movlw 0x01 
movwf PORTD 
call SND_CMD 
movf POSTDEC1,0 
movf INDF1,0 ; shouldn't this be movwf?
movwf PORTD 
call SND_DTA
Other than that since there are no comments in the routines, its difficult to know what you are trying to do. Further, you should not use movf POSTDEC1,0. Instead use movf POSTDEC1,W or ,F as required. It makes the code easier to read for someone is looking at it for the first time.

EDIT: since you are using PK2, step through the code and look at the RAM in a watch window.
 

Thread Starter

RG23

Joined Dec 6, 2010
304
The first subroutine works completely fine

beginning with LFSR 1, h'100'

I store oxFF in four consecutive data memory locations and display them on the four pages of dispay in a single column

In the next subroutine I just access those register locations again and try to display them in the adjacent column

One surprising result I noticed while debugging was the contents of those registers are no longer 0xFF

Even if in the second subroutine there was any issue in the addressing still those contents in 100, 101, 102, 103 shouldn't be affected.

What do you think?
 

JohnInTX

Joined Jun 26, 2012
4,787
Well, I just pulled one as an example, I didn't look all the way through the code for the reasons indicated. The same construct appears in several places.

I don't know why you are moving from *FSR1 to W, decrementing FSR1 then moving *FSR1 to W again. If that's what you intended, we can take a longer look.

EDIT: OK, is that construct to increment FSR1 after INDF? If so, you can shorten it to just POSTINC1, yes? For example, to set the 4 xFF:

Rich (BB code):
lfsr 1, 0x100 ;Fill 4 bytes beginning at 0x100 with FF
setf POSTINC1
setf POSTINC1
setf POSTINC1
setf POSTINC1 ; FSR1 -> byte after the last FF
I also notice you are not resetting FSR1 to start in the 2ed routine. Is that OK?

l
 
Last edited:

Thread Starter

RG23

Joined Dec 6, 2010
304
I figured out the problem

Both subroutines worked ok.

There was an additional subroutine that was writing different data to those register locations

I am now running into another problem

I have data stored in LFSR 1,h'100' consecutive data memory locations

I am trying to store the same data in another memory location at the same time using LFSR 0,h'800'

But every 2nd 8 bit data out of four is getting distorted.

Has anyone tried the indirect addressing involving two FSRs at the same time and transferring the data between them and encountered a similar problem?
 

JohnInTX

Joined Jun 26, 2012
4,787
Has anyone tried the indirect addressing involving two FSRs at the same time and transferring the data between them and encountered a similar problem?
Yes, yes and no in that order. Based on your earlier code, you are not taking full advantage of the FSR capabilities (doing a dummy move to bump the pointer then using indirect - it can be done in one operation).

Use something like this:
Rich (BB code):
 Count equ .10 ;move 10 bytes
 SourceData equ 0x100 ; location of data to move
 DestData equ 0x200 ; where to move it

 lfsr 1,SourceData ; set pointers
 lfsr 2,DestData
 movlw Count ; use W as a counter
loop:
 movff POSTINC1,POSTINC2 ; move *FSR1 -> *FSR2, bump both
 decfsz WREG,F ; count
 bra loop
 return
BTW: To avoid inadvertent writes to INDF clobbering RAM, good programming practice would suggest that you 'park' your FSRs after using them i.e. point them to some unused RAM. Better programming practice would have you put some known bytes at that location, a signature. Inspecting these for a changed signature would indicate you are misusing the FSRs (writing indirect when/where you don't expect) but at least you clobber unused RAM.
 
Last edited:
Top