Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC program size and hex file size confusion

Status
Not open for further replies.

sonar_abhi

Member level 1
Joined
Mar 15, 2016
Messages
36
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
380
Hello guys!

I am a newbie in PIC programming. I have written a simple program and compiled it in mikroC selecting PIC16F877A as the microcontroller. The generated hex file is of 5kB size. But in the mikroC compiler, the compiler shows the following messages:

  • Used RAM (bytes): 2 (1%) Free RAM (bytes): 350 (99%)
  • Used ROM (program words): 57 (1%) Free ROM (program words): 8135 (99%)

Essentially my program size on the chip is only 57 words ~ 0.1kB, but when I build it, the generated hex file is 5kB in size.

The funny part is that I am able to burn the 5kB hex file in PIC16f72 which has a program memory of 2kB

Can anybody please explain what is going on?

Regrads,

Ace
 

Hex file isn't binary file, it's size is not the binary size.

I guess, mikroC is simply writing a complete flash image, including the unused part. 2k binary makes >4k hex. Need to inspect the file to know exactly.
 

Used RAM (bytes): 2 (1%) Free RAM (bytes): 350 (99%)
Used ROM (program words): 57 (1%) Free ROM (program words): 8135 (99%)

As you can see, your program has grabbed all the RAM and ROM but have used only 1% of them. This is common behaviour. Another program cannot be allowed on the same memory space.

The hex file is basically a memory dump but most of it will be filled with zeros.
 

The hex file is basically a memory dump but most of it will be filled with zeros
.

A hex file isn't a memory dump, it's a text file containing an ASCII hex list of addresses, data and CRC values. A memory image would be the same size as the compiled code, possibly rounded up to a 16 or 256 byte boundary.

.hex is an industry standard way of storing information to be programmed into a device but the programming hardware has to divide the lines of text into fields containing record type, length, address the data is to be stored at, the data itself and then a checksum at the end. All the information is stored as text characters and that is why the file is so much bigger than the compiled code itself.

Brian.
 

I am able to burn the 5kB hex file in PIC16f72 which has a program memory of 2kB

Although the main question is already answered, just a remark: The PIC16F72's program memory isn't 2K-bytes as you've certainly meant, but rather 2K-program words, as emphasized at the compilation log:

Used RAM (bytes): 2 (1%) Free RAM (bytes): 350 (99%)
Used ROM (program words): 57 (1%) Free ROM (program words): 8135 (99%)
 

.A hex file isn't a memory dump, it's a text file containing an ASCII hex list of addresses, data and CRC values. A memory image would be the same size as the compiled code, possibly rounded up to a 16 or 256 byte boundary..

You are right, this is not an image file, but is a basic memory dump produced by the compiler after compiling and linking and is a simple text file containing both the address and value. In this way, the loader that reads the hex file and puts it in the memory is very compact and simple. This program that reads the hex file and copies it in the PIC memory finally exits and the program counter is loaded and activated.

Even if we can write the memory values in a windows (or any other OS compatible) file, the files will have lots of headers and other relevant informations written in the file and the actual file size will never be equal to the actual number of bytes the program will load into memory.

It is a nice feature that we can edit this hex file- sometimes that is useful.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top