To meet your curiosity about knowing the use of hex fiel (in fact, it is called Intel-Hex Formatted File), I am putting below some information with an example of an assembly program.
1. The following assembly program ignites (ON) a LED connected at PB0-pin of a stand-alone ATmega328P MCU (not the one that is on the UNO Board).
RESET: ldi r16, 0xFF ;
out ddrb, r16 ;all port lines of Port-B are output lines
sbi portb, pb0 ;Logic High is asserted on PB0-pin of Port-B
2. The following are the binary codes for the ASM (assembly) Codes of Step-1 (created using ATmel Studio 7.0)
000000 ef0f RESET: ldi r16, 0xFF
000001 b904 out ddrb, r16
000002 9a28 sbi portb, pb0
3. The following is the Intel-Hex formatted file (containing 3 frames) for the ASM Program of Step-1 (created using ATmel Studio 7.0)
4. Use of Intel-Hex formatted file.
(1) In Step-2, there are 6-bytes code/data for the progrm, which must be loaded into the flash memory of the MCU. The code/data are:
(2) We can see that the code/data are packed within Frame-2 of Step-3. The codes/data are packed in this parcular way so that they could be transmitted from PC to the target receiver using UART Port; where, each symbol/digit/character goes in its ASCII code. Thus, the symbols/digits of Frame-2 travel as:
3A 30 36 30 30 30 30 30 30 30 46 45 46 30 34 42 39 32 38 39 41 37 44 (spaces are shown for clarity)
(ASCII codes for these symbols : 0 6 0 0 0 0 0 0 0 F E F 0 4 B 9 2 8 9 A 7 D of Frame-2)
The receiver does the reverse processing and extract the original code/data from the ASCII codes and put them into the flash. (How? It is beyond the discussion of this scope.)
5. Meanings of various fields of Intel-Hex formatted file. Here, we take Frame-2 as an example
==> : 06 0000 00 0FEF04B9289A 7D
(a) (b) (c) (d) (e) (f)
Field-a: Colon says to the receiver that a new frame is to arrive from the transmitter
Field-b: Indicates number of code/data (here 6-byte) bytes in this frame and
are contained in Field-e
Field-c: Indicates byte-oriented/organized memory location number of the flash from which the code/data bytes will get stored.
Field-d: When it is 00, it indicates that there are still more frames to arrive from transmitter. When it is 01 (see the last frame), it indicates that there are no more frames to arrive from transmitter.
Field-e It indicates the actual code/data bytes that have come from transmitter (lower bte comes first).
Field-f: It is check sum (CHKSUM). The transmitter sends it to receiver as the last data byte of the frame to allow the receiver checking the validity of the received frame. The CHKSUM is calculated in the following way:
(i) Add all the bytes from Field-b to Field-e. Thus we have: 0x06 + 0x00 +0x00 + 0x00 +0x0F + 0xEF + 0x04 + 0xB9 + 0x28 + 0x9A = 0x0283 (0x mean hex numbers)
(ii) Discard the carry. There remains: 0x83 (10000011).
(iii) Takes the 2's complement of 0x83 and sends at the end of frame.
==> 01111100 + 1 = 01111101 = 7D