【正文】
下面是對此類 PLC邏輯指令的單片機程序模塊建立過程的分析。因為單片機芯片不同,內(nèi)部的硬件資源也 就不同,目標指令代碼和目標程序框架結構也就不同。然后,定義了基于單片機的 PLC的源程序語句標準集合,提出了源程序語句標準集合的數(shù)組表示方法;定 義了目標代碼集合,提出了用口映射來建立源程序語句標準集合和目標代碼集合之間的關系,為編譯程序結構的實現(xiàn)提供了條件和方法;提出了盲碼預填和盲碼修正的思想提出了依據(jù) M數(shù)組對源程序查錯的思路,通過列表文件名和列表文件的建立、整句識別、語句語法檢查中的 M數(shù)組逐行搜索、核對關鍵詞是否相等、核對語句長度是否正確等一系列環(huán)節(jié),實現(xiàn)對源程序的查錯處理;論述了翻譯過程中向目標文件里裝配固定代碼的過程;論述了翻譯和裝配活動代碼的整體思路和流程;運用 M數(shù)組進行源程序語句的類型識別,初步實現(xiàn)了盯映射的預定位;有效定義了引用名 (位地 址 )的字符轉化函數(shù);分別給出了實現(xiàn)盯映射的第一種程序結構和第二種程序結構,有效的完成了簡單活動代碼和復雜活動代碼的翻譯和目標文件的裝配任務;提出并論述了第一類盲碼修正和第二類盲碼修正的程序實現(xiàn)方法。 關鍵詞 : 單片機,可編程邏輯控制器,編譯程序,盲碼,源程序,目標程序 7 Abstract Sometimes, one kind of extremely inexpensive logic controller is needed in design and the development of the automation device and the integration oelectro—mechanical product. In order to meet this kind of needs. the author carried Oll the hardware and the sofhvare research of having directly realized the ladder diagram logic control with the monolithic microputer. In which. most essential technology is how to design the piler for PLC based on monolithic microputer,and is how to translate PLC instruction source program which conf01Tn ladder diagram logic into monolithic microputer targetprogram. This paper elaborated design theory and the method of the piler for PLC based on the monolithic microputer,has studied the monolithic microputer program module and the target program frame for PLC based on the monolithic microputer,has c ried on the analysis to . elaborated design method for the checking mistaken module as well as the assembly method for goal code, has carried on the analysis to expedmental result and debugging experiment system position for the piler for PLC based on the monolithicmicroputer. First,the research on the monolithic microputer program module for PLC based on the monolithic microputer has been conducted. The alone characteristic frame construction for targetprogram has been constructed. Then. the paper has defined the standard set of the source program sentence for PLC based on the monolithic microputer,proposed the array expression method for the standard setof the source program sentence. The goal code set has been defined. Establishing the relations between the source program sentence standard set and the goal code set with sigma the mapping has been proposed, so that the condition and the method for realization of the pile structure has been provided. A thought ofthe filling blind code in advance and the revising blind code has been proposed。此外在設計中采用盲碼預填及修正技術。實現(xiàn) TIM指令所需要的片內(nèi)資源有:①延時計時器的邏輯位 Ti,位地址 30H. 3FH;②延時計時器的狀態(tài)標志位 Si,位地址 40H. 4FH;⑨延時計時器的軟加 1計數(shù)器 Zi, Zi由兩字節(jié)寄存器組成,由 TO中斷服務程序對其實行加 1計數(shù),可記錄 4位 BCD數(shù),字節(jié) 地址 50H, 51H, 52H, 53H, CNT Ci計數(shù)指令的單片機程序模塊如下: 14 1. 4 PLS. 8 Yi 脈沖微分語句的單片機程序模塊的構建 本系統(tǒng)共設有 8個脈沖微分寄存器。其中,固定代碼的編譯結果基本是固定的。 m iJ是其元素, m i j ? M, m i j為 1字節(jié) ASCII字符,且有子集 Mi ? M Mi: {m?mi2, ??, mik} (1) Mi為 M數(shù)組行元素集合,其前 k— 1個字符組成的字符串記為: String Mi=mi1mi2??mik1 假如 String Mi的值等于基于單片機的 PLC某種源程序語句 (簡稱為“源語句 ) 助記符串中的標識符串,并且 Mi中的元素 mi k的值等于這種源語句長度的 ASCII值, 則稱子集 Mi為這種源語句的標準子集。例如,源程序語句 LD 20共 5 個 ASCII字符 (空格算一個 ASCII字符 ),所以,子集 M1={L, D, , 5)中的最后一 個數(shù)字為 5。目標代碼都是 16進制代碼。其特點是:翻譯時, 一次掃描 源程序文件,逐條翻譯,依 Fi=a(Mi)裝配活動代碼。一旦識別出一個整句,就進行語句語法檢查,并將查錯結果寫入列表文件。 3. 1. 2 列表文件 (. 1st)的建立 下面的程序,先用 fopen,以 rb的方式打開源程序文件。用 c[i1]=ch語句實現(xiàn)源語句字符送 C數(shù)組操作。因此實行 J加 1(做j++:操作 ),到 M數(shù)組的下一行中繼續(xù)搜索。 30 3. 4. 4 錯誤標記寫入錯誤信息文件 在 3. 1. 2中我們已經(jīng)知道指針變量 fp指向源程序文件 (. asm),指針變量 fpl 指向列表文件 (. 1st)。 結果,實現(xiàn)了用 b數(shù)組記錄一個文件名和源程序文件名相同,但擴展名和源程序文件名不同的目標文件名,該目標文件名的擴展名為“. bin。所以,目標文件的擴展名為“. bin。 上例中的標準有: mE4][5]=’\ x06’。 若找不到相同的,則該源程序語句語法不正確。當識別出一個整句時,進行一次語句語法檢查。} If(i36) {b1=2。 y=09H, 其中, 09H值是從源語句 PLS 09中的參數(shù) 09得到, 19H是計算得到。定理 1證畢。 fi。 性質 3: M數(shù)組的行數(shù)等于基于單片機的 PLC語句的條數(shù)。等編譯程序中執(zhí)行“掃描源程序文件,逐條翻譯... 時,得到源程序 提供的定時器初值,再在用正式代碼 (以 MOV指令目標代碼的形式,并含定時器初值 ) 代替相應位置上的盲碼。其功能是將 輸入端的邏輯值暫存在 Gi中,供 SFT指令使用;第二個是對應于 SFT Mi的移位操作 程序模塊,其功能是依據(jù)已知的當前邏輯運算值 (在累加器 C中 ),以及 Hi的值,判斷 16 移位脈沖是否到;當移位脈沖到時,將輸入暫存位 Gi中的值移入移位寄存器 Mi。這是一個對第 i個延時計時器進行邏輯運算處理的模塊,運算的依據(jù)是已知的當前邏輯運算值 (在累加器 C中 )。 (如延時計時器類、脈沖微分類、計數(shù)器類、移位類等 )的單片機程序模塊需十幾條或 幾十條單片機指令組成。 (2)其次,目標程序框架結構也不同。首先,進行了基于單片機的 PLC的單片機程序模塊研究,構建了獨具特點的目標程序框架結構。A mentality of checking mistaken to the source program according to the Marray has been proposed. The processing of the checking mistaken to the source program has been realized through a series of procedure such as the establishment of list filename and list documenL the recognition to entire sentence. the search by line using M array in sentence grammar inspection, the checkup to key word whether equal, the checkup to sentence length whether correct and so on. The process of assembling the fixed code into the goal document during the translation has been elaborated. Overall mentality and the procedure 8 of the translation and the assembly code have been elaborated. The prelocalization of the sigma mapping bycarrying on the type recognition to source program sentence depend on the array M has initially beenrealized. The character transformation function for quotation name(bit address)has been definedeffectively, e first kind of procedure structure and the second kind of procedure structure for realizationsigma mapping has separately been given, so that the translation of the simple active code and the plex active code has effective been pleted, and that the assembly of the goal document has been pleted. The procedure realization method for the first kind of blind code revision and the second kind of blind code revision has been proposed and elaborated. The experimental system which using the research of piler design for PLC based on monolithic microputer has been established. We had carried on the confirmation and pare to the each function of the piler. After the severaI procedure trials。 總之,基于單片機的 PLC編譯程序設計研究是一項具有創(chuàng)造性的工作,需要充分吸 收前人 經(jīng)驗,開創(chuàng)創(chuàng)新,建立新的模型,新的結構,新的方法 1 基于單片機的 PLC的單片機程序模