|
|
View previous topic :: View next topic |
Author |
Message |
johngriswold
Joined: 04 Apr 2018 Posts: 13
|
Header file v. compiled code |
Posted: Fri Apr 20, 2018 12:47 pm |
|
|
I have a sample program I built using the Project Wizard - it's the LED blinking example. Mostly it works, so I use it as a baseline - add stuff until it breaks, then I know the last thing I added is broken.
In the header file I have #if 0 / #else / #endif enclosing IDENTICAL statements. If I change that to #if 1 (thus bringing to bear the same header statements, the program compiles differently.
Header File:
Code: |
#if 1
#include <16LF15313.h>
#device ADC=10
//#use delay(internal=8000000)
#use delay(crystal=20000000)
#define LED PIN_A5
#define XXX PIN_A7
#define DELAY 100
#else
#include <16LF1513.h>
#device ADC=10
//#use delay(internal=8000000)
#use delay(crystal=20000000)
#define LED PIN_A5
#define XXX PIN_A7
#define DELAY 100
#endif
|
Listing with 0:
Code: |
CCS PCM C Compiler, Version 5.077, 39075 20-Apr-18 14:29
Filename: C:\Source\MICROS-2122\ApicTest\led2.lst
ROM used: 51 words (2%)
Largest free fragment is 1997
RAM used: 5 (2%) at main() level
17 (7%) worst case
Stack used: 0 locations
Stack size: 16
*
0000: MOVLP 00
0001: GOTO 018
0002: NOP
.................... #include <led2.h>
.................... #if 1
....................
.................... #include <16LF15313.h>
.................... //////////// Standard Header file for the PIC16LF15313 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16LF15313
....................
.................... #list
....................
.................... #device ADC=10
.................... //#use delay(internal=8000000)
.................... #use delay(crystal=20000000)
0003: MOVLW 20
0004: MOVWF 05
0005: MOVLW 01
0006: MOVWF 04
0007: MOVF 00,W
0008: BTFSC 03.2
0009: GOTO 017
000A: MOVLW 06
000B: MOVWF 78
000C: CLRF 77
000D: DECFSZ 77,F
000E: GOTO 00D
000F: DECFSZ 78,F
0010: GOTO 00C
0011: MOVLW 7B
0012: MOVWF 77
0013: DECFSZ 77,F
0014: GOTO 013
0015: DECFSZ 00,F
0016: GOTO 00A
0017: RETURN
.................... #define LED PIN_A5
.................... #define XXX PIN_A7
.................... #define DELAY 100
....................
.................... #else
....................
.................... #include <16LF1513.h>
.................... #device ADC=10
.................... //#use delay(internal=8000000)
.................... #use delay(crystal=20000000)
.................... #define LED PIN_A5
.................... #define XXX PIN_A7
.................... #define DELAY 100
....................
.................... #endif
....................
....................
....................
....................
.................... //#use rs232(UART1, stream=STREAM_UART_UART1, noinit)
....................
.................... void main()
0018: MOVLB 11
0019: CLRF 12
001A: CLRF 0F
001B: CLRF 11
001C: CLRF 13
001D: MOVLW 70
001E: MOVWF 0D
001F: MOVLB 3E
0020: CLRF 38
0021: MOVLB 13
0022: CLRF 11
0023: CLRF 12
0024: CLRF 13
0025: CLRF 10
.................... {
.................... // setup_uart(9600, STREAM_UART_UART1);
....................
....................
....................
.................... while(TRUE)
.................... {
....................
.................... //Example blinking LED program
.................... output_low(LED);
0026: MOVLB 00
0027: BCF 12.5
0028: BCF 18.5
.................... delay_ms(DELAY);
0029: MOVLW 64
002A: MOVWF 21
002B: CALL 003
.................... output_high(LED);
002C: BCF 12.5
002D: BSF 18.5
.................... delay_ms(DELAY);
002E: MOVLW 64
002F: MOVWF 21
0030: CALL 003
0031: GOTO 027
....................
.................... //TODO: User Code
.................... }
....................
.................... }
0032: SLEEP
Configuration Fuses:
Word 1: 3FFA HS RSTOSC_EXT NOCLKOUT CKS FCMEN
Word 2: 3FFD MCLR PUT NOLPBOR BROWNOUT BORV24 ZCDDIS PPS1WAY STVREN NODEBUG
Word 3: 3F9F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 1FFF BBSIZ512 NOBOOTBLOCK NOSAF NOWRT NOWRTB NOWRTC NOWRTSAF NOLVP
Word 5: 3FFF NOPROTECT
|
Listing with 1:
Code: |
CCS PCM C Compiler, Version 5.077, 39075 20-Apr-18 14:05
Filename: C:\Source\MICROS-2122\ApicTest\led2.lst
ROM used: 47 words (1%)
Largest free fragment is 2048
RAM used: 5 (2%) at main() level
17 (7%) worst case
Stack used: 0 locations
Stack size: 16
*
0000: MOVLP 00
0001: GOTO 018
0002: NOP
.................... #include <led2.h>
.................... #if 0
....................
.................... #include <16LF15313.h>
.................... #device ADC=10
.................... //#use delay(internal=8000000)
.................... #use delay(crystal=20000000)
.................... #define LED PIN_A5
.................... #define XXX PIN_A7
.................... #define DELAY 100
....................
.................... #else // 0
....................
.................... #include <16LF1513.h>
.................... //////////// Standard Header file for the PIC16LF1513 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16LF1513
....................
.................... #list
....................
.................... #device ADC=10
.................... //#use delay(internal=8000000)
.................... #use delay(crystal=20000000)
0003: MOVLW 20
0004: MOVWF 05
0005: MOVLW 01
0006: MOVWF 04
0007: MOVF 00,W
0008: BTFSC 03.2
0009: GOTO 017
000A: MOVLW 06
000B: MOVWF 78
000C: CLRF 77
000D: DECFSZ 77,F
000E: GOTO 00D
000F: DECFSZ 78,F
0010: GOTO 00C
0011: MOVLW 7B
0012: MOVWF 77
0013: DECFSZ 77,F
0014: GOTO 013
0015: DECFSZ 00,F
0016: GOTO 00A
0017: RETURN
.................... #define LED PIN_A5
.................... #define XXX PIN_A7
.................... #define DELAY 100
....................
.................... #endif // 0
....................
....................
....................
.................... //#use rs232(UART1, stream=STREAM_UART_UART1, noinit)
....................
.................... void main()
0018: MOVLB 03
0019: CLRF 0C
001A: CLRF 0D
001B: CLRF 0E
.................... {
.................... // setup_uart(9600, STREAM_UART_UART1);
....................
....................
....................
.................... while(TRUE)
.................... {
....................
.................... //Example blinking LED program
.................... output_low(LED);
001C: MOVLB 01
001D: BCF 0C.5
001E: MOVLB 02
001F: BCF 0C.5
.................... delay_ms(DELAY);
0020: MOVLW 64
0021: MOVLB 00
0022: MOVWF 21
0023: CALL 003
.................... output_high(LED);
0024: MOVLB 01
0025: BCF 0C.5
0026: MOVLB 02
0027: BSF 0C.5
.................... delay_ms(DELAY);
0028: MOVLW 64
0029: MOVLB 00
002A: MOVWF 21
002B: CALL 003
002C: MOVLB 03
002D: GOTO 01C
....................
.................... //TODO: User Code
.................... }
....................
.................... }
002E: SLEEP
Configuration Fuses:
Word 1: 3FC2 HS NOWDT PUT MCLR NOPROTECT BROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1FFF NOWRT NOVCAP STVREN BORV19 NOLPBOR NODEBUG NOLVP
|
Note that the code following main() differs greatly between the two cases.
Note, too, that the fuse map is completely different for each of the cases.
I feel that I don't have a clear grasp of this compiler suite. Is this a bug? Is it me?
Just to add some spice to it, I saved off a copy of the .h file that was causing trouble. I copied the second set of directives, and pasted it over the first, so I KNOW I have identical information.
With the new file, it compiles and generates code OK for both choices. Oh, there must have been an errant character in the first file, right? Nope. WinMerge shows them as identical.
This is really hurting my brain on a Friday afternoon.
Can anybody shed light on this? _________________ John Griswold KK1X
High Tech Migrant Worker |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 20, 2018 12:56 pm |
|
|
They're not identical. You have two different PICs specified.
1. 16LF15313
2. 16LF1513 |
|
|
johngriswold
Joined: 04 Apr 2018 Posts: 13
|
|
Posted: Fri Apr 20, 2018 1:22 pm |
|
|
To add additional spice, I can't reproduce the problem any more, so the problem is likely some failure on my part to do operations in the proper order.
Does anybody have a particular "dance" that assures proper compilation and programming, i.e. always do a clean and a build v. using the rebuild button, or anything like that?
Thanks _________________ John Griswold KK1X
High Tech Migrant Worker |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Apr 20, 2018 1:35 pm |
|
|
gee I use CCS 'through' MPLAB 8v86, I always press F10 to compile
course I'm still confused about HOW the compiler understands your
If 1......
else....
code
Where's the '1' supposed to be IFted to ?
Heck I STILL have SNOW here, on the ground, so I'm not thinking clearly..did get a hotbed in today.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 20, 2018 2:44 pm |
|
|
temtronic wrote: |
Where's the '1' supposed to be IFted to ?
|
It's a quick way to comment out or enable blocks of code (for a debug
or release version, for example) without using block comments:
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Sat Apr 21, 2018 1:43 am |
|
|
The only thing it is much nicer to use meaningful names:
Code: |
#define SMALL_CHIP
#ifdef SMALL_CHIP
#include <PICxxxxx.h>
#fuses xxxxx
#clock
#else
#include <PICyyyyy.h>
#fuses yyyyy
#clock
#endif
|
If you are compiling for two chips, make the define that selects the second have some name that 'says' what chip you are selecting. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sat Apr 21, 2018 5:19 am |
|
|
Thanks for the #if 1 explanation
What got/gets me is the 'unbalanced' IF statement, only one half of the expression is there. Kinda like waiting for the 'other shoe to drop' or a 'one sided' teeter totter, it just looks 'funny' to me.
Have to admit I never use 'choose a processor' code either. Prefer the one project, one PIC method. Then again I started using PICs when they first came out with quartz windows on them |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Sat Apr 21, 2018 12:49 pm |
|
|
His post does have the #if, #else & #endif.
I have several projects, where years after initial design 'later' chips are used, but the sources still have to be compilable for the original chip. A #if like this is reasonable way of handling the switch. |
|
|
johngriswold
Joined: 04 Apr 2018 Posts: 13
|
|
Posted: Wed Apr 25, 2018 9:51 am |
|
|
PCM programmer wrote: | They're not identical. You have two different PICs specified.
1. 16LF15313
2. 16LF1513 |
Boy, do I feel dumb ! I even had another guy look it over to make sure.
PCM Programmer - thank you for giving me my proper comeuppance.
And yes, Ttelmah - when I am doing more "meaningful" work, I use more meaningful names than 1 and 0.
_________________ John Griswold KK1X
High Tech Migrant Worker |
|
|
|
|
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
|