Register goes from 0x00 to 0xFF... ?

Status
Not open for further replies.

RobertD

New Member
Hi folks,

I have a register that has 0 in it, when I move the content of this register to the W register, the 0x00 becomes 0xFF.

Can anyone tell me what is going on?
 
Post your code and state what PIC you are using. DECF temp,W or COMF temp,W could do this.
 
Last edited:
I could be reading from the wrong bank indeed. I'm reading the value from EEPROM, and when I switch it over from the EEPROM register to the W register to work with it, it pops.
 
I could be reading from the wrong bank indeed. I'm reading the value from EEPROM, and when I switch it over from the EEPROM register to the W register to work with it, it pops.

Did you assign EEPROM locations in the last part of your program?
 
Yes, I have assigned 0x75 for the EEPROM location, and reading from it. It's moved from the EEDATA register to the W register then from the W to the SELECT register, which is where I need it, and that's when it goes from 0x00 to 0xFF.

I'm using the 16F88 data sheet EEPROM code for read/write. I get a value from AD which I "andf" with "00001111" and rotate right.

I think I read something about "and" masks that was someting there I had to watch for.

And it doesn't move the W register to the SELECT register when I call for it. Now that's puzzling. I included the SELECT register in the cblock in the beginning. It is at 0x02c, while NEW is at 0x075.


Code:
read
        banksel EEADR 
		movf 	NEW, W ;
		movwf 	EEADR ; Data Memory Address to read
		banksel EECON1 
		bcf 	EECON1, EEPGD; Point to Data memory
		bsf 	EECON1, RD ; EE Read
		banksel EEDATA ; Select Bank of EEDATA
		movf 	EEDATA, W ; W = EEDATA                
	            
        return                       

write
        banksel EECON1 ; Select Bank of EECON1
		btfsc 	EECON1, WR ; Wait for write
		goto 	$-1 ; to complete
		banksel EEADR ; Select Bank of EEADR
		movf 	NEW, W ;
		movwf 	EEADR ; Data Memory Address to write
		movf 	NEW, W ;
		movwf 	EEDATA ; Data Memory Value to write
		banksel EECON1 ; Select Bank of EECON1
		bcf 	EECON1, EEPGD ; Point to DATA memory
		bsf 	EECON1, WREN ; Enable writes
		bcf 	INTCON, GIE ; Disable INTs.
		movlw 	h'55' ;
		movwf 	EECON2 ; Write 55h
		movlw 	h'AA' ;
		movwf 	EECON2 ; Write AAh
		bsf 	EECON1, WR ; Set WR bit to begin write
		bsf 	INTCON, GIE ; Enable INTs.
		bcf 	EECON1, WREN ; Disable writes

       
        return                  ;    

 
;coming from A/D going to EEPROM

            swapf	ADRESH
	movlw	B'00001111'
	andwf	ADRESH
	rrf		ADRESH
	movfw	ADRESH
	movwf	NEW
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…