Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Questions re .inc files & WinPicProg

Status
Not open for further replies.

ljcox

Well-Known Member
I downloaded a PIC 16F88 programme from the internet; both the .asm and associated .hex file.

To cut a long story short, I tried to assemble the .asm in MPLAB but a host of error messages appeared relating to the variables in the floasc.inc file (see the .asm fragment below).

It claims they are not defined even though they appear to be defined in the math16.inc file. (I downloaded these files and the relevant AN notes from the Microchip web site)

So I disassembled the .hex using WinPicProg 1.95e to see if it would help me to resolve the issue.

But, as you can see in the .hex fragment below, it worked well until it reached ORG 0x0800.

After that point, there are no labels in the left hand column.

As I have not used .inc files before, I assumed that there would be sufficient info in them to allow a successful assembly.

Fragment from the disassembled .hex.

Label_006E DECFSZ 0x41 , f
GOTO Label_006E
DECFSZ 0x42 , f
Label_00E0 GOTO Label_006F
RETURN
Label_0062
Label_005D
.
There are 33 labels (& no instructions) at this point, so I deleted 30 to save space.
.
Label_0058
ORG 0x0800
MOVLW 0x82
MOVWF 0x2F
MOVLW 0x09
MOVWF 0x2C
GOTO Label_0070
MOVLW 0x85
MOVWF 0x2F

Fragment from the .asm at the ORG 0x0800 point.

decfsz XF1,f
goto $-1
decfsz XF2,f
goto $-4
return

org 0x800
#include <math16.inc>
#include <floasc.inc>

Start_Process
bcf STATUS,RP1
bcf STATUS,RP0
movlw 0x07
movwf count


My questions are:-

1. Do I need to modify 1 or both .inc files to define the variables?

2. Does anyone know how I can make WinPicProg fully disassemble .hex files beyond the ORG 0x0800?

3. If not, is there other software availabe that will?

Any assistance will be appreciated.
 
Last edited:
Hi Len,

Do you have a link to the original project that you downloaded? Or, can you post the asm file.

Mike.
 
It claims they are not defined even though they appear to be defined in the math16.inc file. (I downloaded these files and the relevant AN notes from the Microchip web site)
#include <math16.inc>
#include <floasc.inc>
When the include files are surrounded with <> symbols, the assembler searches in the include path; usually C:\Program Files\Microchip\MPASM Suite.
If you have stored these include files in the same folder as the asm files of the project surround them with quotes so that the assembler can find them:
#include "math16.inc"
#include "floasc.inc"
You can also use the complete or relative path to the files if they are located somewhere else:
#include "C:\somewhere\math16.inc"
#include "subfolder\floasc.inc"

3. If not, is there other software availabe that will?

You can use MPLAB to do this:
1) Select your PIC in Configure/SelectDevice.
2) Choose File/Import and load the HEX file.
3) Choose View/ProgramMemory.
Note: Some of the labels in the listing will be misleading because of bank switching. ie: TRISA can look like PORTA.
 
kchriste, thanks very much. I had not thought of exploring MPLAB.

Thanks Mike, I'll send you a PM.
 
1. Do I need to modify 1 or both .inc files to define the variables?

There should almost NEVER be any need to modify the INC files, and it would be a bad idea.

2. Does anyone know how I can make WinPicProg fully disassemble .hex files beyond the ORG 0x0800?

As far as I'm aware it does - but if the include files weren't found then there was probably no code there.

3. If not, is there other software availabe that will?

MPLAB will disassemble as well.
 
As far as I'm aware it does - but if the include files weren't found then there was probably no code there.
Thanks Nigel.
Not true.

I disassembled the downloaded .hex code using IC-Prog and 2 versions of WinPicProg. All gave the same result, ie. no labels after 0x800.

But when I disassembled it using MPLAB (by following kchriste's instructions), the Line, Address, Opcode & code were in evidence both before & after 0x800.
So, as far as I can see, there is a problem with WinPicProg.
 
Having looked at the offending code clicky. I think the original programmer had modified the include file and forgotten.

For anyone interested, to get the above to assemble I had to,
In the main file, add the lines,
Code:
P16_MAP1	equ	0
P16_MAP2	equ	1

And in the Float to ascii file I had to change it to,
Code:
float_ascii2
	movlw	2         	;load counter with the number of
	movwf	digit_count     ;significant figures the decimal number	
	goto	float_ascii

float_ascii4
	movlw	4         	;load counter with the number of
	movwf	digit_count     ;significant figures the decimal number	

float_ascii
	movlw	0x88		;BARG= 1000 decimal (floating point)
	movwf 	BEXP            ;fprep.exe was used to get this
	movlw	0x7A            ;floating point representation of 1000
	movwf	BARGB0
	movlw	0x00
	movwf	BARGB1
	movlw	0X00
	movwf	BARGB2


	call	FPM32		;AARG = AARG * 1000
   
	call	INT3232		;AARG  <--  INT( AARG )

	movlw	last_digit
	movwf	FSR		;pointer = address of smallest digit
;	movlw	SIG_FIG         ;load counter with the number of
;	movwf	digit_count     ;significant figures the decimal number	

flo_asclp
This is just my guess at what the code should do given the comments in the main code.

Mike.
 
Thanks Mike, much appreciated.

Nigel,
I’ve deduced why the WinPicProg disassembly function does not work properly after 0x0800.

As you know, the 16F series has a 13 bit programme address. But the GOTO & CALL instructions only carry an 11 bit “intermediate” address, bits 10:0.

Thus, if a CALL or GOTO crosses the 0x0800 boundary, bits 3 and/or 4 in PCLATH must be set or cleared to ensure that the PC is shifted to the correct address.

For example, say there is a CALL instruction at 0x001A and the sub routine is located at 0x0814. The CALL instruction must be preceded and followed by PCLATH changes:-

bsf PCLATH, 3
Call subrout14
bcf PCLATH, 3

This is explained in the PIC specs. For example, see section 4.3 in the PIC 16F62X spec. (page 25 in my version).

I realised this after using MPLAB to disassemble the .hex I mentioned above.

At address 0x0808 it reads:- GOTO 0x11.

But the PIC attaches bits 12:11 from the PC to the “intermediate” address thus the GOTO in fact goes to address 0x0811.

This is explained in the Microchip instruction set paper.

Whoever wrote the WinPicProg disassembly programme did not take these issues into account.

Hence, it inserted a label at 0x0011 rather than at 0x0811. This is why there are no labels in column 1 after 0x0800 and several extraneous labels before 0x0800.

I have tried to be brief, so if anything above is not clear, please ask.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top