【正文】
, an invalid character, parity error or timeout during character reception will cause the partial packet to be declared invalid and discarded. Two packet types are defined: data and endoffile. A data packet contains five fields in addition to the packet header, one of which is a variable length data field. The data field contains program data to be written into the AT89C51 controller in the application. The load address field contains the address at which the data is to be written. The endoffile packet contains the same fields as the data packet, except that the data field is empty. This packet type has special meaning to the programmer, as explained below. Any packet which contains an invalid record type, record length or checksum is invalid. Program data accumulated during the processing of an invalid packet is discarded. The programmer sends a NAK to the transmitter to signal reception of an invalid packet and resumes polling for a valid packet header. Receipt of the first valid data packet causes the programmer to interrupt the application controller. The controller responds to the interrupt by abandoning execution of its usual program and displaying a message indicating that programming is taking place. If this is the first valid data packet since power was applied or an endoffile packet was received, the programmer asserts the control signals necessary to erase the program memory in the application controller. The programmer then places the controller in programming mode. The first and subsequent valid data packets are dissected as they are received and the data which they contain is programmed into the application controller at the address indicated in the packet load address field. After programming, the data is read back from the controller and verified against the received packet data. Successful verification indicates that programming was successful, causing the programmer to send ACK to the transmitter. The programmer then resumes polling for a valid packet header, subject to the thirty second reset delay. If programming fails, the programmer sends CAN to signal the transmitter to abort the file transfer. The modem drops the line and the programmer returns to sleep, waiting for the next call. The application controller is left in programming mode, preventing it from executing the inplete or invalid program which it contains. It is important to note that invalid packets are NEVER programmed into the application controller. To do so would require that the program memory in the controller be pletely erased before the error could be corrected, causing the nonrecoverable loss of all previous program data. Upon receipt of an endoffile packet, the programmer returns its control outputs to the inactive, power on state, allowing the application controller to begin execution of the new program. The programmer then resumes polling for a valid packet header, subject to the thirty second reset delay. If a valid packet is received prior to the expiration of the thirty second delay, another programming cycle begins, which can only be terminated by the reception of a valid endoffile packet. If the reset delay expires prior to the reception of a valid endoffile packet, the modem will drop the line and the programmer will return to sleep, waiting for the next call. In this case, the application controller is left in programming mode, preventing it from executing its program. To return the application to normal operation, another call must be received, and a valid program file uploaded, terminated by an endoffile packet. 單片機(jī)在編程電路中的應(yīng)用 本應(yīng)用指南說(shuō)明了 Atmel AT89C51 是可在線(xiàn)可編程的微控制器。此應(yīng)用軟件可以到 Atmel 進(jìn)行下載 。 RST 在 編程期間必須為高電平。 在編程過(guò)程中, AT89C51 的 I / O 端口是用于模式應(yīng)用程序,地址和數(shù)據(jù)選擇的,可能需要該控制器從應(yīng)用的電路隔離。一個(gè)多路復(fù)用器可用于信號(hào)源之間進(jìn)行選擇,適用于任何一方的應(yīng)用電路或編程控制器電路的信號(hào)。 應(yīng)用實(shí)例 此應(yīng)用程序有在電路重新編程時(shí)將結(jié)果以圖表的形式顯示的簡(jiǎn)單能力。在第二個(gè)模式,信息在信息窗口中右到左移動(dòng)顯示??娠@示字符的 ASCII 碼,范圍為 20H5FH。 編程器在休眠時(shí),既不會(huì)驅(qū)動(dòng),也不會(huì)加載應(yīng)用程序。 編程器的編程需要獲得所有數(shù)據(jù)表中記錄的 AT89C51 的 I / O 端口。 在應(yīng)用程序的正常運(yùn)作時(shí),控制器端口 0, 1 個(gè)分別在顯示器上提供數(shù)據(jù)和控制信號(hào)。鎖存持有的顯示控制信號(hào)在編程過(guò)程中不反應(yīng),從而消除端口 0 和 2 由于程序控制器的活 動(dòng)造成操作失誤。 為確??刂凭€(xiàn)顯示在已知的狀態(tài)前鎖定, AT89C51 的外部中斷是用來(lái)允許程序控制器在復(fù)位之前向應(yīng)用程序發(fā)出信號(hào)。雖然這個(gè)應(yīng)用程序是沒(méi)有必要的,它可能在某些 應(yīng)用中必須指出,在編程過(guò)程中不會(huì)擾亂外圍電路的狀態(tài)。一個(gè)MAXIM MAX232 線(xiàn)路驅(qū)動(dòng)器 /接收器產(chǎn)生 RS 232 水平,而只需要 5 伏的電源系統(tǒng)。示例應(yīng)用程序在這種環(huán)境下可正常運(yùn)行。 商業(yè)電話(huà)線(xiàn)遠(yuǎn)程編程 。 本地配置 測(cè)試配置的本地配置包括一臺(tái) IBM 個(gè)人電腦級(jí)的計(jì)算機(jī)連接到與 Hayes 兼容的,普羅米修斯 1200 波特的調(diào)制解調(diào)器。 Prom Plus 版本 ,是一個(gè)商業(yè)數(shù)據(jù)通信軟件包,用于配置調(diào)制解調(diào)器,建立通訊設(shè)置參數(shù),并建立與遠(yuǎn)程調(diào)制解調(diào)器的鏈接。 FTP 模式發(fā)送和接收的是用數(shù)字 4 和 5,如流程圖所示。如果校驗(yàn)和錯(cuò)誤,程序員通過(guò)發(fā)送一個(gè) NAK 來(lái)否定。 程序控制器可能通過(guò)發(fā)送一個(gè) CAN 來(lái)響應(yīng)數(shù)據(jù)包, CAN 表明一個(gè)不可恢復(fù)的錯(cuò)誤發(fā)生,而 發(fā)射機(jī)應(yīng)立即中止文件傳輸。 編程后,數(shù)據(jù)從控制器讀回并對(duì)接收的數(shù)據(jù)包進(jìn)行驗(yàn)證。由于 AT89C51的編程和擦除時(shí)間可以很容易地吸收, FTP 發(fā)送和等待的性質(zhì)允許跨包延遲。 OH 將 8051 絕對(duì)目標(biāo)文件轉(zhuǎn)換為為等效的 ASCII 十六進(jìn)制目標(biāo)文件。新的程序就被下載并嵌入到應(yīng)用程序中的 AT89C51 的編程。是程序控制器不會(huì)影響到程序直到一個(gè)新的程序應(yīng)用程序被下載。上電時(shí),程序控制器判定 DTR,斷定為 DTR 后調(diào)制解調(diào)器響應(yīng)。如果建立了連接,調(diào)制解調(diào)器發(fā)送一個(gè)代碼,喚醒程序控制器。在復(fù)位延遲時(shí)間傳入是被忽略的。數(shù)據(jù)包包含五個(gè)領(lǐng)域,除了包報(bào)頭,是一個(gè)可變長(zhǎng)度的數(shù)據(jù)字段。這包類(lèi)型對(duì)程序控制器具有特殊的意義,如下所述。 第一個(gè)有效數(shù)據(jù)的接收 引起編程器中斷應(yīng)用程序控制器。 當(dāng)接收到第一個(gè)和其后的有效數(shù)據(jù)程序包時(shí),將它們分開(kāi),它們包含的數(shù)據(jù)被編程到程序包負(fù)載地址域中的地址中的應(yīng)用控制器內(nèi)。 如果編程失敗,編程器向傳送者發(fā)送信號(hào) CAN 中止文件傳輸。這樣做將要求錯(cuò)誤被糾正之前,編程器中的記憶程序被徹底抹掉,造成先前所有數(shù)據(jù)的不可恢復(fù)。 如果復(fù)位在收有效末端文件之前終止,那么調(diào)制解調(diào)器會(huì)掉線(xiàn),編程器停止工作,等待下一次傳