| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| jruibarroso 
 
 
 Joined: 07 Jan 2006
 Posts: 64
 Location: Braga
 
 
			        
 
 | 
			
				| Why doesn't count more than 255 ?? |  
				|  Posted: Fri Jan 20, 2006 11:10 am |   |  
				| 
 |  
				| I'm working with a 16F877 , made a counter but it don't pass over (seconds) >255 countings, it step to 0..1..2..3..4..255..0..1. Any body can help me with this ?? Thank you ALL 
 int seconds;
 
 #int_rtcc
 clock_isr() {
 output_high(LED);
 if(--int_count==0)
 {
 output_low(LED);
 ++seconds;
 int_count=INTS_PER_SECOND;
 }
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Fri Jan 20, 2006 11:11 am |   |  
				| 
 |  
				| Look at what sizes variables can hold. An _integer_, by default, is an 'int8', and can only hold 0....255.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| jruibarroso 
 
 
 Joined: 07 Jan 2006
 Posts: 64
 Location: Braga
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Fri Jan 20, 2006 11:59 am |   |  
				| 
 |  
				| ok, thank you very much 
 but there is another problem...
 
 i changed int seconds; to int16 seconds;
 
 but returns an erros on this line
 
 printf(lcd_putc,"\f %U TEMPERATURA %2U\n", seconds , temp);
 
 do you know why ?
 |  | 
	
		|  | 
	
		| newguy 
 
 
 Joined: 24 Jun 2004
 Posts: 1924
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 20, 2006 12:18 pm |   |  
				| 
 |  
				| Since 'seconds' is now a long integer (int16), you must use '%lu' not '%u' in your printf statement. 
 I recommend that you take some time to peruse the manual and/or online help.
 |  | 
	
		|  | 
	
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 20, 2006 12:22 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | i changed int seconds; to int16 seconds;
 
 | 
 
 Ok, then you used %U within the string to indicate an unsigned 8 bit variable.
 If you defined int16 seconds, printf expect %lu.
 
 Read the CCS Compiler Manual, it will show you the diferent formats for the built-in function printf().
 
 
 Humberto
 |  | 
	
		|  | 
	
		| jruibarroso 
 
 
 Joined: 07 Jan 2006
 Posts: 64
 Location: Braga
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Fri Jan 20, 2006 12:43 pm |   |  
				| 
 |  
				| THANK you !!  |  | 
	
		|  | 
	
		|  |