【正文】
該控制系統(tǒng)在產(chǎn)業(yè)領(lǐng)域運(yùn)行良好,并通過(guò)控制單個(gè)步進(jìn)電機(jī)啟動(dòng) /停止和正轉(zhuǎn) /反轉(zhuǎn)旋轉(zhuǎn)。在這里介紹查詢方式通信。在傳送數(shù)據(jù)前先聯(lián)絡(luò)地址碼 ,如地址碼正確則傳送數(shù)據(jù) ,否則繼續(xù)聯(lián)絡(luò)地址碼。在編寫(xiě)程序之前 ,制定其雙方通信協(xié)議是十分重要的 ,否則將無(wú)法保證通信數(shù)據(jù)的可靠性 ,從而失去通信的意義。 ( 4)關(guān)閉串口,供其他程序使用。第二種方法是 調(diào)用Windows API(應(yīng)用程序接口)函數(shù),此函數(shù)是由操作系統(tǒng)提供,以提供大量的功能。因此,串口中斷設(shè)置為“關(guān)閉”狀態(tài)的單片機(jī),將它設(shè)定為“開(kāi)”狀態(tài)的數(shù)據(jù)后再發(fā)送數(shù)據(jù)。否則,單片機(jī)判定接收到的數(shù)據(jù)是不是“停止”指令,如果是這樣,它發(fā)出“停止”指令驅(qū)動(dòng)系統(tǒng),如果沒(méi)有,它便退出中斷。 圖 3 主要中斷服務(wù)子程序流程圖 C 判斷指令的子程序 PC 微機(jī)發(fā)送數(shù)據(jù)到單片機(jī)。當(dāng)串口中斷程序接收到指定的數(shù)據(jù)時(shí),便退出串行口中斷。為了充分利用單片機(jī),以減少 CPU 的占用時(shí)間,提高溝通效率 ,控制程序?qū)⑹俏覀儠?huì)及時(shí)響應(yīng)和控制的對(duì)象,通訊程序?qū)⒌玫絻?yōu)化。串行通信模塊的硬件電路如圖 2所示。 MAX232芯片有一個(gè)電壓轉(zhuǎn)換器,它可以改變 +5V 的電壓至所需的電壓。 MAX232外圍需要 4個(gè)電解電容 C C C C4,是內(nèi)部電源轉(zhuǎn)換所需 電容。 MAX232芯片簡(jiǎn)介 MAX232是 Maxim 公司的產(chǎn)品,它是路徑接收和驅(qū)動(dòng) IC 芯片。常見(jiàn)的 TTL 電平和 RS232電平之間的電平轉(zhuǎn)換芯片是MCI1488和 MCI1489。新一代的計(jì)算機(jī)有一個(gè)九針連接器( DB9),這樣就可以通過(guò)這個(gè)九針連接器來(lái)連接 RS232串行端口。在接口電路和計(jì)算機(jī)接口芯片中大都為 TTL 或 CMOS 電平 ,所以在通信時(shí) ,必須進(jìn)行電平轉(zhuǎn)換 ,以便與 RS232C 標(biāo)準(zhǔn)的電平匹配。 RS232C 標(biāo)準(zhǔn) RS232C 是美國(guó)電子工業(yè)協(xié)會(huì) (EIA)正式公布的 ,在異步串行通信中應(yīng)用最廣的標(biāo)準(zhǔn)總線。 USB 接口和 IEEE1394具有傳輸速度快的優(yōu)點(diǎn),但是有一些電腦和操作系統(tǒng)并不支持這種接口。在智能傳感器 IC 設(shè)計(jì)中,在傳感器和信號(hào)處理電路以外,通訊接口電路也可發(fā)揮重要角色。通過(guò)對(duì) 8250的初始化編程,可 以控制串行數(shù)據(jù)傳送格式和速度。而異步通信應(yīng)用于傳送速度在 50到 19200波特之間,是比較常用的傳送方式。 大多數(shù)串行端口使用 RS232C 標(biāo)準(zhǔn) ,它指定了一個(gè) 25針或 9針的連接器。 為了檢測(cè)數(shù)據(jù)已被正確發(fā)送,一個(gè)可選的校驗(yàn)位可以同數(shù)據(jù)位在一起。一個(gè)停止位可以是一位,一個(gè)半位,或兩位。 開(kāi)始傳輸時(shí),設(shè)備先發(fā)送一個(gè)起始位,其次是數(shù)據(jù)位。它的缺點(diǎn)是傳送速度低。它表現(xiàn)為一些設(shè)備使用串口連接到計(jì)算機(jī)。相反,一個(gè)并行端口一次發(fā)送和接收 8位數(shù)據(jù),使用 8個(gè)單獨(dú)的電線。正是考慮到在控制系統(tǒng)中需傳遞的數(shù)據(jù)量多,而單次傳輸?shù)臄?shù)量少,因此在控制系統(tǒng)中選擇串口通信的方法,簡(jiǎn)化了硬件結(jié)構(gòu)并節(jié)約了所需的成本。并行通信可以同時(shí)傳輸大量的數(shù)據(jù),具有傳送速度快的優(yōu)點(diǎn)。一般來(lái)說(shuō),一個(gè)完整的通信系統(tǒng)由發(fā)射器,接收器,轉(zhuǎn)換數(shù)據(jù)接口和傳輸數(shù)據(jù)通道所構(gòu)成。 if not, it quits the interrupt. D. The processing subprogram of send interrupts The processing subprogram of send interrupts is responsible to send data to the puter, sending interrupt state is off in the general. When the munication program pletely deals with data sent by PC microputer, the symbol “1” can be written to send buffer. As the puter receives the symbol “1”, it is said that single chip puter executes pletely the introduction sent by PC microputer. Therefore the serial port interrupt is set as “off” state by the single chip microcontroller and it is set “on” state again after the data are sent. So the single chip microputer returns to main program and waits for receiving instructions. V. THE DESIGN OF COMMUNICATION PROGRAM OF PC MICROCOMPUTER AND SINGLE CHIP MICROCOMPUTER In order to realize the system software easily grafted and uniformity, the program of upper puter is designed using the Boland C++ Builder as a programming tool in the control system s the Boland C++ Builder as a programming tool for PC programming. The serial port munication can be utilized in two ways: First, register ponents, C++ Builder does not in itself provide a separate serial munication ponent, but it can be obtained through registered Microsoft MSComm32 ponents, in which it is relatively simple for VB, VC in this way. The second method is called Windows API (Application Program Interface) function, in which this function is provided by the operating system in order to provide a lot of executive function. The program steps are followed: (1) Setting by munication protocol and opening the serial port, which is called initialization, then blocking the other programs to use the serial port. (2) Configuring the serial port. (3) Transmitting data by the serial port to and fro, verifying data during transmission. (4) Closing the serial port as no needing it so that other program uses. The subinterface is simple, in which the setting on subinterface parameters are defaults, such as baud rate that single chip munication module has been set to 2400Bps and that the baud rate is set to 2400Bps in the puter settings on the ports. The PC microputer has two ports called as serial port COM1 and COM2 generally, so the program can automatically identify serial port so that it can send and receive data and instructions successfully. Serial munication program includes two aspects, one is MCS51 microcontroller munication program, on the other hand for the PC, the munication process. In the 9 preparation processes, the development of the two protocols is very important, otherwise it will not guarantee the reliability of data munications, and thus lose the meaning of munication. The munication protocol is agreed as follows: 1) The serial munication baud rate is 1200bps. 2) The frame format is: a start bit, eight data bits, a programmable ninth bit (this bit is sent and received address / data flag), and one stop bit. 3) Set the address of the microcontroller code F1H. Contact before sending the data in the address code, such as the address code is the correct transmission of data, or to contact the address code. 4) no parity. The munication of data accumulation and verification of the method, that is, each carrying one set of data (number of custom, is set to 100), a cumulative and whether the correct checksum, the right to send you back to the 00H, or loopback FFH. 5) munication can interrupt transmission and query. Here are ways to search for in the munication. 6) PCcontact for the initiative to contact MCS 51 microcontroller. 7) PC machine using COM2 munications. VI. CONCLUSION The hardware of serial port munication is