PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 07-04-2009, 11:54 PM   #1
thaithien
Đệ tử 7 túi
 
Tham gia ngày: Aug 2007
Bài gửi: 213
:
Đọc file hex ?

Mình đọc bài về file hex và giải mã của nó nhưng chưa hiểu lắm.Việc đọc file hex có thể giúp chúng ta dịch ngược mã được không?Mình biết là đã có phần mềm dịch ngược file hex sang mã máy rồi nhưng hãy làm bằng tay thử xem.Đây là cái bài nguyên văn tiếng anh:
================================================== ==================
Hex File Format
The purpose of assemblers and compilers is to convert application source code into a
data format that can be used by a programmer to load the application into a PIC micro-
controller. The most popular format (used by Microchip and most other programmers,
including the two presented in this chapter) is the Intel 8-bit hex ?le format.
When an application is built (assembled or compiled), a hex ?le is generated. It may
seem unnecessary to explain this, but the ?le is referred to as a “hex” ?le because that
is the ?lename extension given to the generated ?le. For example, a simple application
hex ?le could look like:
:10000000FF308600831686018312A001A101A00B98
:0A0010000728A10B07288603072824
:02400E00F13F80
:00000001FF
************************************************** *************************************************
TABLE 4.1 THE FUNCTION OF THE OFFSETS ON EACH LINE OF A HEX FILE
OFFSET FROM
START OF LINE FUNCTION
0 Always : and used to indicate the start of a new line.
1–2 Two times the number of 2-byte instructions on the line in
hexadecimal with most signi?cant digit ?rst. There can be up
to eight instructions (for a value of 16 or 10 hexadecimal).
3–6 Two times the starting address for the instructions on the line.
The address has the most signi?cant digit ?rst and the least
signi?cant digit last.
7–8 The line type (00 = data, 01 = end).
10–13 The ?rst instruction to be programmed into the PIC
microcontroller. The data format is loaded with the ?rst
2 bytes representing the 2 least signi?cant nybbles of the
instruction and the next 2 bytes being the 2 most signi?cant
nybbles representing the most signi?cant nybbles.
14–17, . . . Additional instructions on the line.
Last 2 The checksum of the contents of the line.


************************************************** *************************************************
Each line consists of a starting address and data to be placed starting at this address.
The offsets of each line have their own functions, which are explained in Table 4.1.
Each pair of characters makes up an ASCII byte, with the most signi?cant nybble
coming ?rst, followed by the least signi?cant nybble. Some of the data is represented


by 4 bytes—which will translate to 2 bytes (16 bits) of actual data—with each pair of
bytes used to make up a byte of data or address.
The next 4 bytes (characters) indicate twice the starting address of the data on the line.
If there was a break in the code, say an instruction at address 0 and a break until address
4, the hex ?le would look something like:
:020000000728CF
:0800080029150B1109008316F4
After each instruction is loaded into the PIC microcontroller’s program memory, an
internal counter is incremented. When a line is ?nished, this counter is usually at the cor-
rect value for the next line, but if it is not, it is incremented until it is the same as the line’s
address. This means that if there are gaps in the application, the addresses will be left
unprogrammed.
Note that the second line ends at address 8 boundary (the next line of data will start
at address 0x008, the following one at 0x010, and so on). This is not necessary, but a
convention used by the MPASM assembler.
The next 2 bytes specify the line type. Normally, this is 00, indicating that the line
is data, but when it is 01, it indicates that the line is the end of the ?le.
The instruction data bytes follow the data type bytes. Each 4 bytes represents the
instruction that is to be loaded into the PIC microcontroller’s program memory.
Depending on the PIC microcontroller architecture used, 12 or 14 bytes are required for
the instruction, but 16 bits will always be used to store the instruction, with the top 4
or 2 bits, respectively, being zeros. Unlike the address bytes, the instruction bytes are
saved in Intel format, which means the ?rst 2 bytes are the least signi?cant bytes of the
instruction. The instruction bytes are not multiplied by two.
The last 2 bytes of each line of the hex ?le are the checksum of the line. This value
is used to con?rm the contents of the line and ensure that when all bytes of the line are
summed the least signi?cant 8 bits are equal to 0x000. This value is calculated by taking
the least signi?cant 8 bits of the sum of the line and subtracting it from 0x0100.
Using the second line of the example hex ?le above:
:0A0010000728A10B07288603072824
The sum of all the bytes (except for the checksum bytes is):

The sum of all the bytes (except for the checksum bytes is):
0A
00
10
00
07
28
A1
0B
07
28
86
03
07
+ 28
--------
1DC
The least signi?cant 8 bits (0x0DC) are taken away from 0x0100 to get the checksum:
0x0100
- 0x00DC
--------
0x0024
This calculated checksum value of 0x024 is the same as the last 2 bytes of the
original line.
While I’ve called the 2 checksum bytes the end of each line in the hex ?le, each line in
the ?le is actually terminated by an ASCII carriage return (0x0100) and line feed (0x0100)
combination. This is important for homegrown programmers: because of the different way
?les can be read, the line feed character may or may not be present. This caused me quite
a few problems with the YAP programmer, as I will detail later in the chapter.
================================================== ==================
thaithien vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 06:57 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam