Problem with MOVF instruction

Status
Not open for further replies.

Zener_Diode

New Member
hey.
this is my program.

main:

clrf STATUS
bsf STATUS,5 ;select bank1

ISR:
;external INT
bcf STATUS,5 ;select bank1
bcf STATUS,6
movlw 20h
movwf FSR
movlw 0h
movf FSR,w

after movf FSR,W I got w=BDh instead of w=20h does anyone know why???
Thanks ahead.
 
FSR and INDF are used for indirect adressing (see the datasheet), you don't seem to be mentioning INDF?. I'm also a little concerned about 'ISR:', if this is an interrupt service routine it's lacking in anything that would make it viable.
 
Nigel Goodwin said:
FSR and INDF are used for indirect adressing (see the datasheet), you don't seem to be mentioning INDF?. I'm also a little concerned about 'ISR:', if this is an interrupt service routine it's lacking in anything that would make it viable.

I know. I tryed to write any other register instead of FSR, the same result, the value of W chaged with changing value of the register I put at the instruction. But the W value after the instruction didn't correct. and I have no idea why.
what can I do? according datasheet it should work excelent
 
Side note: Why is this forum so riduculously slow? Page loads but unable to post because the little images take all day to catch up!! Clear throat and unball fist.


Ok, FSR is only for addressing, its is the address locator of the target ram. INDF is the data channel. You want to read whatever FSR points to, then read INDF. You want to write to whatever FSR points to, then write to INDF.
 
Zener_Diode said:

Obviously not enough in this case.

Zener_Diode said:
what can I do? according datasheet it should work excelent

Try to explain to yourself how one can use the following code to select bank1.

Code:
ISR:
;external INT
bcf STATUS,5 ;select bank1
bcf STATUS,6
 

This part of your code
Code:
bcf STATUS,5 ;select bank1
bcf STATUS,6
movlw 20h
movwf FSR
movlw 0h
movf FSR,w

Returned 0X20 in W when MPLAB simulated on a 16F628A as expected.

What PIC are you using?
 
RabbitResearch said:
Returned 0X20 in W when MPLAB simulated on a 16F628A as expected.

What PIC are you using?

I tryed in this PIC (16F628A) and it return 0xBD. with 16F84 and 16F84A it returns me the same 0xBD.
what is the verion of your MPLAB???
 
It happens only to the last instruction.
if I add movlw 30h after movf FSR,w I got right result from movf instruction and wrong result from movlw 30h instruction.

Does someone know why????
 
If you have a movlw 30h then W will contain 30h unless the code that is being executed is not the code you have written. Hence my question.

If you post your complete code then maybe we can help. Posting bits of code just confuses everyone.

Mike.
 
Zener_Diode said:
I tryed in this PIC (16F628A) and it return 0xBD. with 16F84 and 16F84A it returns me the same 0xBD.
what is the verion of your MPLAB???


I'll show you mine if you show me yours (here is my complete code)
Code:
	list      p=16f628A           ; list directive to define processor
	#include <p16F628A.inc>       ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

;***** VARIABLE DEFINITIONS
w_temp        EQU     0x71        ; variable used for context saving 
status_temp   EQU     0x72        ; variable used for context saving

;**********************************************************************
	ORG     0x000             ; processor reset vector
	goto    main              ; go to beginning of program
	

	ORG     0x004             ; interrupt vector location
	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	movwf	status_temp       ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere


	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt

main


	bcf STATUS,5 ;select bank1
	bcf STATUS,6
	movlw 20h
	movwf FSR
	movlw 0h
	movf FSR,w


	goto	main		  ;loop forever, remove this instruction, for test only


	END                       ; directive 'end of program'

This does what I said it does - returns 0x20 after executing the last movf - Where is your complete code?

(MPLAB 7.30)
 

try to cancle thr last instruction, "goto main" and tell me what in the result...
 
Zener_Diode said:
try to cancle thr last instruction, "goto main" and tell me what in the result...

If you cancel that last instruction the program restarts from the beginning.
 
Zener_Diode said:
If u cancle the last istruction the program should stop running.

Nigel is correct - if you do not like my "goto main", change it to a plain "nop" before you let your program run off to no-where (or better yet a nop followed by a goto $). It still returns 0x20 as expected. If you had posted your full code, earlier, you would have had your answer earlier. Best of Luck - I'm moving on
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…