【正文】
r it has much characteristic, such as moderate price, the hardware simple, so it is used to be a voltage converter. The hardware circuit of serial munication module is shown in Figure 2. Figure 2. The hardware circuit of serial munication module IV. THE SOFTWARE DESIGN OF SERIAL PORT COMMUNICATION The munication program of the single chip microputer municates with PC puter by interrupt and PC puter is called as main controller. When the single chip puter receives the data signals sent by PC puter, then it calls interrupt service program. The flowchart of the interrupt service main subprogram is shown in Figure 3. In order to fully exploit the efficiency of single chip puter to minimize CPU ?time occupied by munication, the control program will be we will promptly respond to and control 6 objects. The munication program will be optimized. The subprogram of serial port interrupt for receiving data, the subprogram for sending stepbystep impulse, the subprogram for judging instruction and the subprogram foe sending data. A. The subprogram of serial port interrupts for receiving data The subprogram of serial port interrupts for receiving data is mainly responsible for receiving data sent by PC microputer and storing the data into allocated memory (it does not deal with data so as to reduce the time taken up by interruptions). The data received by the single chip microputer includes little information, such as speed, steps and on/off instructions, and the buffer is large enough to send the puter, so the software shake hands protocol is omit so as to raises the CPU utilization. When the program of serial port interrupt receives the specified data, it exits the serial port interrupt. B. The subprogram of sending the stepbystep impulse Using countertimer of the single chip microcontroller timer 0, as the fixed times plete, the port is negated so as to periodically generate the driving pulses. The timer 0 begins to count from initial value to 65535, then the interrupt subprogram of timer 0 is called, in which the port is negated to generate a driving pulse. Meanwhile, the single chip microputer loads again the initial value which is sent by the PC microputer by serial munication. 7 Figure 3. The flowchart of the interrupt service main subprogram C. The subprograms of judging instruction The program of judging instruction is set on the serial port interrupt program to be called. The PC microputer sends data to the single chip microputer. After the single chip microputer receives data, it sets the RI higher and called the serial port interrupt subprogram, in which the first data is processed. If the first data is a digital symble”48”, the serial port interrupt subprogram sets higher, then the next five bytes data is used to ensure the stepbystep motor? speed and steps. If the first data is a digital symble”49”, it means that the stepbystep motor reverses, then the single chip microputer receives the speed and steps information. Otherwise the single chip microputer judges that the 8 received data is not STOP instruction, if so, it sends “stop” instruction to the drive system。 1 中文 4700 字 The Designing of Serial Communication Based on RS232 Abstract This paper discussed the principle of serial munication mainly, proposed the design method based on RS232, designed the hard circuit of serial munication, and realized the programming to PC Microputer and single chip microputer by using assembly language and C++ Builder separately. Keywords: serial munication。 R1OUT, R2OUT should take MCS 51 in the serial receive pins RXD1 corresponding RS232C level T1OUT, T2OUT should be connected to PCreceiver RD。在電機的控制系統(tǒng)中, PC 微機被稱為上位機,而由單片機所控制的步進電機被稱為下位機。從 IBM 個人電腦和兼容式電腦的時代開始,幾乎所有的計算機都配有 一個或多個串行端口和一個并行端口。 二、串口 通訊的簡述 串行通信是指通信的發(fā)送方和接收方之間數(shù)據(jù)信息的傳輸是在單根數(shù)據(jù)線上 ,以每次一個二進制位移動。發(fā)送器和接收器必須設(shè)置為相同的數(shù)據(jù)通信比特或正確的比特率。使用校驗位提供了一個基本的機制,以檢測已發(fā)送數(shù)據(jù)是否損壞,但不保證檢查數(shù)據(jù)本身的錯誤。在串行通信前 ,發(fā)送方和接收方要約定具體的數(shù)據(jù)格式和波特率 (通信協(xié)議 )。它們都有著自身的特點,同時也分別適用于不同的的應(yīng)用領(lǐng)域。 RS232C 標準定義了 25根引線 ,對于一般的雙向通信 ,只需使用串行輸入 RXD,串行輸出 TXD和地線 GND。 圖 的端口 三、串行通信端口的硬件設(shè)計 單片機應(yīng)用的是 TTL 電平,而 PC 機的 RS232串行接口使用的是標準的串行接口標準,所以兩者的電氣性能規(guī)格是不一致的。 MAX232芯片內(nèi)部有一個電源電壓變換器 ,可以把輸入的 +5V 電源變換成RS232C 輸出電平所需177。不僅如此,它有許多優(yōu)點,比如價格適中,硬件簡單等等。 A 串口中斷子程序用于接收數(shù)據(jù) 用于接收數(shù)據(jù)的串行端口的中斷子程序,主要是將 PC 微機接收和發(fā)送的數(shù)據(jù)存儲到分配的內(nèi)存中(不進行數(shù)據(jù)處理,以減少中斷的時間)。如果第一個數(shù)據(jù)是一個數(shù)字標記“ 48”,串行口中斷分程序設(shè)置 ,那么接下來的五個字節(jié)的數(shù)據(jù)用于確保步進電機的速度和步驟。 五、 PC 和單片機通信程序的設(shè)計 為了方便地實現(xiàn)系統(tǒng)軟件移植和統(tǒng)一,上位機程序的設(shè)計使用作為控制系統(tǒng)編程工具 C++Builder , C++Builder PC 的編程工具。微機具有兩個串口,一般稱為 COM1和 COM2,以便程序可以自動識別串行端口,利于端 口成功的發(fā)送和接收數(shù)據(jù)和指令。數(shù)據(jù)的通信采用累加和校驗的方法 ,即每傳送一組數(shù)據(jù) (個數(shù)自定 ,設(shè)為 100個 ),校驗一次累加和是否正確 ,正確則返回 00H,否則返回 FFH。 18 參考文獻 [1]樊一支 ,姜文祥 ,陳梨園 .串行通信控制的 C++生成和 :清華大學出版社 ,2020年 ,第218 [2]茍?zhí)K艾 .C++ .北京 :北京希望電子出版社 ,2020年 ,第 16 [3]劉艷玲 .使用 MAX232進行的 MCS51單片機與 PC 機之間的的通信 .天津科技 ,1999年 ,第研究所 15( 2) :第 5658 [4]楊國霞 .采用消息方式處理串口與主程序間的通訊 .雜志 :促進科技 ,2020年 ,河北省科學院卷 .18(4):220223頁 [5]黎步銀 ,江盛林 ,盧重 ,周東祥 .基于 C 語言的串行通信程序設(shè)計 .作者 :Transcluction 技術(shù) ,2020,卷 .(2)第 6566 [6]王志忠 .單片機和 PC 機之間的串行通信 .現(xiàn)代電子技術(shù) ,2020,119,第 6870