| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Torello 
 
 
 Joined: 29 Sep 2006
 Posts: 128
 
 
 
			    
 
 | 
			
				| #byte access of FSR0H / FSR0L |  
				|  Posted: Fri Oct 23, 2009 8:07 am |   |  
				| 
 |  
				| Hi, 
 Does any body know why the compiler clears FSR0H when loading FSR0L ? First I though it might be a odd/even adress thing but if I do the same loading on for example ADCON1/2 then it does it OK...
 
 
  	  | Code: |  	  | #byte  FSR0H   = 0xFEA
 #byte  FSR0L   = 0xFE9
 #byte ADCON1   = 0xfc1
 #byte ADCON2   = 0xfc0
 
 ....................
 ....................   FSR0H = 0x11;
 00212:  MOVLW  11
 00214:  MOVWF  FEA
 ....................   FSR0L = 0x22;
 00216:  CLRF   FEA                       <<< OUCH! WHY????
 00218:  MOVLW  22
 0021A:  MOVWF  FE9
 ....................
 ....................   AdCON2 = 0x55;
 0021C:  MOVLW  55
 0021E:  MOVWF  FC0
 ....................   ADCON1 = 0x44;
 00220:  MOVLW  44
 00222:  MOVWF  FC1
 ....................
 
 | 
 
 regards,
 Edwin.
 Compiler version PCWHD 4.099
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Oct 23, 2009 2:12 pm |   |  
				| 
 |  
				| The quick solution is just to change the order of the lines. |  | 
	
		|  | 
	
		| Torello 
 
 
 Joined: 29 Sep 2006
 Posts: 128
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Oct 23, 2009 4:03 pm |   |  
				| 
 |  
				| I though of that solution too.  But knowing -why- it is done give me more confidence that this solution stays working in the future.... 
 A support request on this issue has been submitted to CCS.
 
 (any thoughts are of course still welcome)
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Sat Oct 24, 2009 2:56 am |   |  
				| 
 |  
				| I think you will find the reason is that the compiler already has a _16bit_ variable, called 'FSR0L' defined. 
 The #byte directive works in two different ways. If no variable exists with the name being used, it created an 8bit variable, and maps it to the defined address. If a variable already exists with the name, it maps this variable to the address.
 So the compiler already has a 16bit variable called FSR0L defined, and when it sees the #byte directive, maps _this_ to the address. Hence when you access FSR0L, it accesses both addresses. Two solutions:
 
 1) Use your own name to avoid any possible clash with the compiler 'My_FSR0L' for example.
 
 2) Assume that the compiler's FSR0L, does not 'mind' being at the FSR address, and use:
 
  	  | Code: |  	  | 
 #byte  FSR0L   = 0xFE9
 
 FSR0L = 0x1122;
 
 | 
 
 Best Wishes
 |  | 
	
		|  | 
	
		| Torello 
 
 
 Joined: 29 Sep 2006
 Posts: 128
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Oct 27, 2009 9:27 am |   |  
				| 
 |  
				| Were is this _16bit_ applied on the definitions of Fsr's? 
 Solution 1 does -not- work:
 
  	  | Code: |  	  | ....................
 ....................   My_fsr0H = make8(Dbf,1);
 00342:  MOVFF  213,FEA
 ....................   My_fsr0L = make8(Dbf,0);
 00346:  MOVF   x12,W
 00348:  CLRF   FEA
 0034A:  MOVWF  FE9
 ....................
 
 | 
 
 Solution 2 to be used
   
 Thanks,
 Edwin
 |  | 
	
		|  | 
	
		|  |