| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| jbmiller 
 
 
 Joined: 07 Oct 2006
 Posts: 73
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				| missing RETLW in a function |  
				|  Posted: Mon Mar 12, 2007 9:16 am |   |  
				| 
 |  
				| Okay, I'm NOT a great C programmer but always muddle through ..until now.. I have 3 very similar functions( wait for the desired logic level on a pin, then return). Two compile fine, the third NEVER has the RETLW code! Even if I rearrange the order of the functions, the 'waithd' NEVER gets the RETLW code on the end. 
 source code....
 
 void	waithd()	{				// waithd
 while(!input(pin_b1)){			// wait for high clock
 }						//
 }						//
 
 void	waitlc()	{				// waitlc
 while(input(pin_b0)){			// wait for low clock
 }						//
 }						//
 
 
 
 void	waithc()	{				//waithc
 while(!input(pin_b0)){			//wait for high clock
 }						//
 }						//
 
 
 
 listing code.......
 0000                00407 .................... void	waithd()	{				// waithd
 0000                00408 .................... 	while(!input(pin_b1)){			// wait for high clock
 04AD 1683           00409 BSF    03,5
 04AE 1486           00410 BSF    06,1
 04AF 1283           00411 BCF    03,5
 04B0 1C86           00412 BTFSS  06,1
 04B1 2CAD           00413 GOTO   4AD
 0000                00414 .................... 	}						//
 0000                00415 .................... 	}						//
 0000                00416 ....................
 0000                00417 .................... void	waitlc()	{				// waitlc
 0000                00418 .................... 	while(input(pin_b0)){			// wait for low clock
 04A3 1683           00419 BSF    03,5
 04A4 1406           00420 BSF    06,0
 04A5 1283           00421 BCF    03,5
 04A6 1806           00422 BTFSC  06,0
 04A7 2CA3           00423 GOTO   4A3
 0000                00424 .................... 	}						//
 04A8 3400           00425 RETLW  00
 0000                00426 .................... 	}						//
 0000                00427 ....................
 0000                00428 ....................
 0000                00429 ....................
 0000                00430 .................... void	waithc()	{				//waithc
 0000                00431 .................... 	while(!input(pin_b0)){			//wait for high clock
 049D 1683           00432 BSF    03,5
 049E 1406           00433 BSF    06,0
 049F 1283           00434 BCF    03,5
 04A0 1C06           00435 BTFSS  06,0
 04A1 2C9D           00436 GOTO   49D
 0000                00437 .................... 	}						//
 04A2 3400           00438 RETLW  00
 0000                00439 .................... 	}						//
 
 
 Any idea WHY this occours? No errors on the compile, rest of code is ok.
 
 Thanks Jay
 |  |  
		|  |  
		| rnielsen 
 
 
 Joined: 23 Sep 2003
 Posts: 852
 Location: Utah
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 12, 2007 9:31 am |   |  
				| 
 |  
				| I believe that if the function is only called from one place that it will have a GOTO at the end.  If it is called from multiple places, in your code, then it will have a RETLW.  Try calling the third function from a second location and see if it changes things. 
 Ronald
 |  |  
		|  |  
		| kevcon 
 
 
 Joined: 21 Feb 2007
 Posts: 142
 Location: Michigan, USA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 12, 2007 9:36 am |   |  
				| 
 |  
				| What code comes after this block? 
 I think you'll find a RETLW is not needed because the waithd function ends at address 04B1 and there is probably another instruction right after it.
 |  |  
		|  |  
		| JAY B MILLER Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Tue Mar 13, 2007 5:33 am |   |  
				| 
 |  
				| Oops forgot that the listing isn't linear,following the memory.Thanks for the pointers about this.Used MSDOS 'sort' program to make things easier for me to read and follow. Crazy part is that the machine code version works fine(program diddles the PS2 KBD LEDS) and no amount of coaxing a C program will work.FAST_IO,embedding working asm code with #asm..#endasm. Very frustrating to say the leastAlmost as much 'fun' as the Microchip '24/7  tech support'. However I do have patience and will eventually get C to control the LEDs.
 Thanks for your support guys.
 Jay
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |