![]() |
|
Tài trợ cho PIC Vietnam |
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 |
![]() |
#1 |
Đệ 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. ================================================== ================== |
![]() |
![]() |
![]() |
#2 |
Đệ tử 7 túi
Tham gia ngày: Aug 2007
Bài gửi: 213
: |
Không ai quan tâm tới vấn đề này sao,tui thấy nó cũng hay đó chứ mặc dù chưa hiểu kỹ lắm.Phân tích được cái này mình sẽ hiểu thêm được con pic hoạt động như thế nào khi đọc dữ liệu từ file hex đó
|
![]() |
![]() |
![]() |
#3 | |
Trưởng lão PIC bang
|
Trích:
Nếu câu trả lời là không thì bạn làm việc đó để làm gì. Thân,
__________________
Biển học mênh mông, sức người có hạn. Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau: http://www.picvietnam.com/forum/showthread.php?t=1263 |
|
![]() |
![]() |
![]() |
#4 |
Đệ tử 7 túi
Tham gia ngày: Aug 2007
Bài gửi: 213
: |
Có lẽ là không nhưng nếu được thì cũng hay.Giá sử như có một chương trình rất hay nhưng anh không có source của nó mà chỉ nắm giữ file hex thôi.Lúc đó giá sử không có trình dịch ngựoc ra mã máy thì sao.Em chỉ thắc mắc thêm thế thôi chứ không cố ý đặt nặng vấn đề này.Thanks anh đã trả lời.
|
![]() |
![]() |
![]() |
#5 |
Nhập môn đệ tử
Tham gia ngày: Mar 2010
Bài gửi: 3
: |
Chào mấy anh!
Em mới học PIC, đã viết code asm cho pic24h, và dịch ra file hẽ thành công. Nhưng mà Thầy em bảo tìm hiểu về định dạng của file .hex này.Theo như em tìm hiểu thì định dạng này theo INTEL .HEX FORMAT FILE. Có anh nào hiểu về cái định dạng này không ạ? Xin chỉ giáo cho em với ,em cần lắm! XIn cảm ơn mấy anh nhiều! |
![]() |
![]() |
![]() |
|
|