Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question of Indirect Addressing in 16F1824

Status
Not open for further replies.

kahjoo

Junior Member level 2
Junior Member level 2
Joined
Jul 23, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,456
Hi,

Currently I'm porting the current coding using in 16F685 to new MCU 16F1824 which we need 32MHz for internal clock. However, I’ve problem of porting the “Indirect Addressing” function.

Below is the original code and the register address for reference:-

The register address are in Bank2. As the 16F1824 having the 16bits of FSR(FSRh,FSRl), how does the correct coding to be used for indirect addressing?

Can someone show me the corret way?

Code:
;data storage on tx
tx_byte0		equ	0x123	
tx_byte1		equ	0x124
tx_byte2		equ	0x125	
tx_byte3		equ	0x126	
tx_byte4		equ	0x127	
tx_byte5		equ	0x128	
tx_byte6		equ	0x129
tx_byte7		equ	0x12A	
tx_byte8		equ	0x12B	
tx_byte9		equ	0x12C	
tx_byte10		equ	0x12D	
tx_byte11		equ	0x12E
tx_byte12		equ	0x12F	


;data tx/rx on ic2ic
ic_byte0		equ	0x143
ic_byte1		equ	0x144
ic_byte2		equ	0x145
ic_byte3		equ	0x146
ic_byte4		equ	0x147
ic_byte5		equ	0x148
ic_byte6		equ	0x149
ic_byte7		equ	0x14A
ic_byte8		equ	0x14B
ic_byte9		equ	0x14C
ic_byte10		equ	0x14D
ic_byte11		equ	0x14E
ic_byte12		equ	0x14F


;command register
reg0			equ	0x71
reg1			equ	0x72
reg2			equ	0x73



transfer_tx_byte_ic
	bsf		STATUS,IRP
	movlw	tx_byte0		;from
	movwf	reg1
	movlw	ic_byte0		;to
	movwf	reg2
;--- priority setting
	bcf		ic_byte0,0
	btfsc	priority_f
	bsf		ic_byte0,0
;---

;---transfer_byte
	movlw	.13		;13bytes count
	movwf	reg0
transfer_byte_01
	movf	       reg1,w
	movwf	FSR
	movf	       INDF,w
	movwf	temp
	movf	       reg2,w
	movwf	FSR
	movf	       temp,w
	movwf	INDF
	incf	       reg2,f
	incf	       reg1,f
	decfsz      reg0,f
	goto	        transfer_byte_01

transfer_byte_end
	bcf		STATUS,IRP
	return
 
Last edited:

The FSRxH selects the bank of memory, you then use FSRxL to select the location in the bank.
The code should work if you first init FSRxH with the correct memory bank, and increment FSRxL to step through the bank.
 

Hi,

Thanks. I've tried to edit the original with min change of the original code.
Do you see any problem of the modified code below?

Code:
transfer_tx_byte_ic
	movlw	0x01
	movwf	FSR0H		;FSR to Bank 2 select
	movlw	tx_byte0		;from
	movwf	reg1
	movlw	ic_byte0		;to
	movwf	reg2

transfer_byte
	movlw	.13		;13bytes count
	movwf	reg0
transfer_byte_01
	movf	reg1,w
	movwf	FSR0L
	movf	INDF0,w
	movwf	temp
	movf	reg2,w
	movwf	FSR0L
	movf	temp,w
	movwf	INDF0
	incf	reg2,f
	incf	reg1,f
	decfsz	reg0,f
	goto	transfer_byte_01
transfer_byte_end
	clrf	FSR0H	;switch back to Bank 0
	return
 

Try using Mplab Sim to step through the code and use the watch window to see the memory.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top