| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Output from compiler | 
			 
			
				 Posted: Tue Apr 24, 2007 2:23 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hello super forum,
 
 
I'am new as C programmer (old ASM-programmer).
 
I have problem with power-up and the I/O pins
 
As default the pins at portA at the PIC16F883 is inputs at power-up.
 
When I look one pin "RA1" I can see this pin is going High at power-up.
 
I use non-fixed I/O so it have to be an input until I will use it as another.
 
 
I look in the .LST file and I can see that there is some code that the compiler has generated before it comes to the C-code I have written.
 
In line 0031 0032 and 0033 the pin RA1 and RA2 is set to an output
 
and that is before my code.
 
Where did that code come from and why is the compiler changing the trisA itself without my control.
 
 
.................... void main() { 
 
0019:  CLRF   04
 
001A:  BCF    03.7
 
001B:  MOVLW  1F
 
001C:  ANDWF  03,F
 
001D:  MOVLW  61
 
001E:  BSF    03.5
 
001F:  MOVWF  0F
 
0020:  BSF    03.6
 
0021:  MOVF   09,W
 
0022:  ANDLW  C0
 
0023:  MOVWF  09
 
0024:  BCF    03.6
 
0025:  BCF    1F.4
 
0026:  BCF    1F.5
 
0027:  MOVLW  00
 
0028:  BSF    03.6
 
0029:  MOVWF  08
 
002A:  BCF    79.5
 
002B:  BSF    79.4
 
002C:  MOVLW  02
 
002D:  MOVWF  7B
 
002E:  MOVLW  04
 
002F:  MOVWF  7A
 
0030:  BCF    03.6
 
0031:  MOVF   05,W
 
0032:  ANDLW  F9
 
0033:  MOVWF  05
 
0034:  MOVF   07,W
 
0035:  IORLW  01
 
0036:  ANDLW  FD
 
0037:  MOVWF  07 | 
			 
		  | 
	
	
		  | 
	
	
		
			treitmey
 
 
  Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI   USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 24, 2007 7:42 am     | 
				     | 
			 
			
				
  | 
			 
			
				You didn't show your c code so I can only assume the compiler is makeing this up as its default code.  These lines should get it back to working again.
 
 
 	  | Code: | 	 		    
 
setup_adc_ports(NO_ANALOGS);
 
setup_adc(ADC_OFF);
 
#use fast_io(a)
 
set_tris_a(0xFF);
 
 | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 24, 2007 1:37 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Here is the C-code and the lst-file
 
 
#include <16F883.h>
 
#device ICD=TRUE
 
 
#FUSES INTRC_IO                           // Internal RC Osc, no CLKOUT
 
#FUSES NOLVP                               // No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 
#FUSES NOWDT                    // No Watch Dog Timer
 
#FUSES PUT                         // Power Up Timer (64ms)
 
 
#use delay(clock=4000000)
 
 
#define tp_rod_led PIN_C1  // test
 
 
 
// ******************** main ********************
 
void main() {
 
  while (true) {
 
    output_high(tp_rod_led); 
 
    delay_ms (4);
 
 
    output_low (pin_A1); 
 
    delay_ms (1);
 
    output_high (pin_A1); 
 
    delay_ms (1);
 
    output_float(pin_A1);
 
    delay_ms (1);
 
 
    output_low (tp_rod_led);
 
    delay_ms (5); 
 
  }
 
}
 
 
-------------------------------------------------------
 
and the lst-file after compilation:
 
 
0000:  NOP
 
0001:  MOVLW  00
 
0002:  MOVWF  0A
 
0003:  GOTO   019
 
....................  
 
....................  
 
.................... #include <16F883.h> 
 
.................... //////// Standard Header file for the PIC16F883 device //////////////// 
 
.................... #device PIC16F883 
 
.................... #list 
 
....................  
 
.................... #device ICD=TRUE 
 
....................  
 
.................... #FUSES INTRC_IO                           // Internal RC Osc, no CLKOUT 
 
.................... #FUSES NOLVP                               // No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 
 
.................... #FUSES NOWDT                    // No Watch Dog Timer 
 
.................... #FUSES PUT                         // Power Up Timer (64ms) 
 
....................  
 
.................... #use delay(clock=4000000) 
 
0004:  MOVLW  21
 
0005:  MOVWF  04
 
0006:  BCF    03.7
 
0007:  MOVF   00,W
 
0008:  BTFSC  03.2
 
0009:  GOTO   018
 
000A:  MOVLW  01
 
000B:  MOVWF  78
 
000C:  CLRF   77
 
000D:  DECFSZ 77,F
 
000E:  GOTO   00D
 
000F:  DECFSZ 78,F
 
0010:  GOTO   00C
 
0011:  MOVLW  4A
 
0012:  MOVWF  77
 
0013:  DECFSZ 77,F
 
0014:  GOTO   013
 
0015:  GOTO   016
 
0016:  DECFSZ 00,F
 
0017:  GOTO   00A
 
0018:  RETLW  00
 
....................  
 
.................... #define tp_rod_led PIN_C1  // test 
 
....................  
 
....................  
 
.................... // ******************** main ******************** 
 
.................... void main() { 
 
0019:  CLRF   04
 
001A:  BCF    03.7
 
001B:  MOVLW  1F
 
001C:  ANDWF  03,F
 
001D:  MOVLW  61
 
001E:  BSF    03.5
 
001F:  MOVWF  0F
 
0020:  BSF    03.6
 
0021:  MOVF   09,W
 
0022:  ANDLW  C0
 
0023:  MOVWF  09
 
0024:  BCF    03.6
 
0025:  BCF    1F.4
 
0026:  BCF    1F.5
 
0027:  MOVLW  00
 
0028:  BSF    03.6
 
0029:  MOVWF  08
 
002A:  BCF    79.5
 
002B:  BSF    79.4
 
002C:  MOVLW  02
 
002D:  MOVWF  7B
 
002E:  MOVWF  7A
 
002F:  BCF    03.6
 
0030:  MOVF   05,W
 
0031:  IORLW  02
 
0032:  ANDLW  F9
 
0033:  MOVWF  05
 
0034:  MOVF   07,W
 
0035:  IORLW  01
 
0036:  ANDLW  FD
 
0037:  MOVWF  07
 
....................   while (true) { 
 
....................     output_high(tp_rod_led);  
 
0038:  MOVLW  FF
 
0039:  BCF    03.5
 
003A:  MOVWF  20
 
003B:  BCF    20.1
 
003C:  MOVF   20,W
 
003D:  BSF    03.5
 
003E:  MOVWF  07
 
003F:  BCF    03.5
 
0040:  BSF    07.1
 
....................     delay_ms (4); 
 
0041:  MOVLW  04
 
0042:  MOVWF  21
 
0043:  CALL   004
 
....................  
 
....................     output_low (pin_A1);  
 
0044:  BSF    03.5
 
0045:  BCF    05.1
 
0046:  BCF    03.5
 
0047:  BCF    05.1
 
....................     delay_ms (1); 
 
0048:  MOVLW  01
 
0049:  MOVWF  21
 
004A:  CALL   004
 
....................     output_high (pin_A1);  
 
004B:  BSF    03.5
 
004C:  BCF    05.1
 
004D:  BCF    03.5
 
004E:  BSF    05.1
 
....................     delay_ms (1); 
 
004F:  MOVLW  01
 
0050:  MOVWF  21
 
0051:  CALL   004
 
....................     output_float(pin_A1); 
 
0052:  BSF    03.5
 
0053:  BSF    05.1
 
....................     delay_ms (1); 
 
0054:  MOVLW  01
 
0055:  BCF    03.5
 
0056:  MOVWF  21
 
0057:  CALL   004
 
....................  
 
....................     output_low (tp_rod_led); 
 
0058:  BCF    20.1
 
0059:  MOVF   20,W
 
005A:  BSF    03.5
 
005B:  MOVWF  07
 
005C:  BCF    03.5
 
005D:  BCF    07.1
 
....................     delay_ms (5);  
 
005E:  MOVLW  05
 
005F:  MOVWF  21
 
0060:  CALL   004
 
....................   } 
 
0061:  GOTO   03B
 
.................... } 
 
0062:  GOTO   062
 
 
Configuration Fuses:
 
   Word  1: 0CF4   INTRC_IO NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT IESO FCMEN NOLVP DEBUG
 
   Word  2: 3FFF   NOWRT BORV40 | 
			 
		  | 
	
	
		  | 
	
	
		
			treitmey
 
 
  Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI   USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 24, 2007 3:35 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| I don't have a 16F883 but I ran it through a mplab simulator and it didn't show the tris A at address 0x85 being changed.  Which part of the asm do you think is changing the tris A ? 31,32,33 don't say anything about 0x85 | 
			 
		  | 
	
	
		  | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 24, 2007 11:59 pm     | 
				     | 
			 
			
				
  | 
			 
			
				The asm-lines 0030 to 0033 changing the trisA.
 
remember that in line 001E, bank 1 is selected so movwf 05 actually is 85.
 
 
I'am wondering where all the lines from "void main" until "while" is coming from. Some of them like line 001A is already cleared by uP itself by power-up. | 
			 
		  | 
	
	
		  | 
	
	
		
			treitmey
 
 
  Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI   USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Apr 25, 2007 7:53 am     | 
				     | 
			 
			
				
  | 
			 
			
				I'm not an ASM guy, so I can't argue that point.
 
 
But why didn't the mplab simulator show tris A changing?
 
 
The code before main is put in from the compiler for your convenience.
 
You can't turn it off as far as I know.
 
Just override it with the set_tris command before your main while. | 
			 
		  | 
	
	
		  | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Apr 25, 2007 8:41 am     | 
				     | 
			 
			
				
  | 
			 
			
				I have tried single stepping the C-program from reset with the ICD2 from microchip in a another program, and it has the same result. If I look at the TRISA I can see that the TRISA is FF after reset but after the  mysterious mentioned code the TRISA is changed.
 
My hardware construction don“t accept that I changed later with a TRIS command and I am a little disappointed about the compiler, because I know that it's no problem in assembler coding.
 
 
Is it a compiler failure?
 
 
Does anyone know why these start asm-lines is there? | 
			 
		  | 
	
	
		  | 
	
	
		
			treitmey
 
 
  Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI   USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Apr 25, 2007 10:26 am     | 
				     | 
			 
			
				
  | 
			 
			
				Will this fix the problem?
 
 	  | Code: | 	 		  #include <16F883.h>
 
#use delay(clock=4000000)
 
#fuses HS,NOWDT,NOLVP
 
#use fast_io (a)
 
#byte port_a = 0x05
 
#byte tris_a = 0x85
 
//======================= Main ==============================
 
void main(void)
 
{
 
  tris_a=0xFF;
 
  setup_adc_ports(NO_ANALOGS);
 
  setup_adc(ADC_OFF);
 
  while(1)
 
  {
 
    tris_a=0b11111101;// only output is A1
 
    port_a=0b11111101;// output_low(PIN_A1);
 
  }
 
} | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Apr 25, 2007 11:51 pm     | 
				     | 
			 
			
				
  | 
			 
			
				No, the "bad code" before our code still is there, but the time with bad TRIS value is a little smaller.
 
Thanks for trying to help, but I think I will try to ask CCS about it. | 
			 
		  | 
	
	
		  | 
	
	
		
			Mortenc
 
 
  Joined: 22 Feb 2007 Posts: 55
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Apr 30, 2007 11:40 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Solution/information to "treitmey" who tried to help me and others with interrest.
 
 
The problem is now solved.
 
The compiler is updated to the last version 4.033. (My version was 4.032)
 
This fix the problem with the bad startup code. | 
			 
		  | 
	
	
		  | 
	
	
		
			treitmey
 
 
  Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI   USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue May 01, 2007 7:58 am     | 
				     | 
			 
			
				
  | 
			 
			
				Ohhhh hell.    
 
Now it all makes sense.  You were using the beta compiler.
 
I was using 3.249  ((I need to ask for that stuff up-front))
 
I'm glad it working for you now. | 
			 
		  | 
	
	
		  | 
	
	
		 |