【正文】
在此再次向路老師表示深深的謝意!第52頁(yè) 共54頁(yè)附頁(yè)附錄一制作PCB版的線路圖:PCB實(shí)物圖:PC機(jī)與單片機(jī)連接實(shí)物圖整體智能交通燈控制系統(tǒng)實(shí)物圖:附錄二 Introduction AT89C51DescriptionThe AT89C51 is a lowpower, highperformance CMOS 8bit microputer with 4K bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmel’s highdensity nonvolatile memory technology and is patible with the industrystandard MCS51 instruction set and pinout. The onchip Flash allows the program memory to be reprogrammed insystem or by a conventional nonvolatile memory programmer. By bining a versatile 8bit CPU with Flash on a monolithic chip, the Atmel AT89C51 is a powerful microputer which provides a highlyflexible and costeffective solution to many embedded control applications.Function characteristicThe AT89C51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16bit timer/counters, a five vector twolevel interrupt architecture, a full duplex serial port, onchip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Powerdown Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset.Pin DescriptionVCC:Supply voltage.GND:Ground.Port 0:Port 0 is an 8bit opendrain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance 0 may also be configured to be the multiplexed loworder address/data bus during accesses to external program and data memory. In this mode P0 has internal 0 also receives the code bytes during Flash programming,and outputs the code bytes during programverification. External pullups are required during programverification.Port 1Port 1 is an 8bit bidirectional I/O port with internal Port 1 output buffers can sink/source four TTL 1s are written to Port 1 pins they are pulled high by the internal pullups and can be used as inputs. As inputs,Port 1 pins that are externally being pulled low will source current (IIL) because of the internal 1 also receives the loworder address bytes during Flash programming and verification.Port 2Port 2 is an 8bit bidirectional I/O port with internal Port 2 output buffers can sink/source four TTL 1s are written to Port 2 pins they are pulled high by the internal pullups and can be used as inputs. As inputs,Port 2 pins that are externally being pulled low will source current, because of the internal 2 emits the highorder address byte during fetches from external program memory and during accesses to external data memory that use 16bit addresses. In this application, it uses strong internal pullupswhen emitting 1s. During accesses to external data memory that use 8bit addresses, Port 2 emits the contents of the P2 Special Function 2 also receives the highorder address bits and some control signals during Flash programming and verification.Port 3Port 3 is an 8bit bidirectional I/O port with internal Port 3 output buffers can sink/source four TTL 1s are written to Port 3 pins they are pulled high by the internal pullups and can be used as inputs. As inputs,Port 3 pins that are externally being pulled low will source current (IIL) because of the 3 also serves the functions of various special features of the AT89C51 as listed below:Port 3 also receives some control signals for Flash programming and verification.RSTReset input. A high on this pin for two machine cycles while the oscillator is runnin。另外經(jīng)過(guò)這2個(gè)多月的鍛煉,培養(yǎng)了我們獨(dú)立思考問(wèn)題,解決問(wèn)題的能力。在此,我要感謝我的同學(xué),正是由于你們的幫助和支持,我才能克服一個(gè)一個(gè)的困難和疑惑,其中特別要感謝王超塵同學(xué),雖然我們不是同一組,但在設(shè)計(jì)前期他給予了我很大的幫助。我借此機(jī)會(huì)向路老師表示衷心的感謝!在畢業(yè)設(shè)計(jì)的整個(gè)過(guò)程中,我深切地體會(huì)到了,實(shí)踐是理論運(yùn)用的最好檢驗(yàn)。路老師治學(xué)嚴(yán)謹(jǐn),品格高尚,平易近人。首先是我的指導(dǎo)老師路子赟。短短的2個(gè)多月中,我們通過(guò)自己的努力,在老師的精心指導(dǎo)下,完成了畢業(yè)設(shè)計(jì)。實(shí)驗(yàn) 系統(tǒng)不足是功能過(guò)于簡(jiǎn)化,很不完善,時(shí)間設(shè)定中沒(méi)有黃燈的等待閃爍時(shí)間,以及自動(dòng)根據(jù)車流改變紅綠燈時(shí)間,此外,雖然具有初步的視覺(jué)智能,但還比較低級(jí),如能進(jìn)行流量檢測(cè),運(yùn)用到交通的控制中,來(lái)計(jì)算交通控制點(diǎn)之間的距離,對(duì)于更合理的安排紅、綠燈的持續(xù)時(shí)間,使城市的交通管理更加人性化。紅燈倒計(jì)時(shí)期間,對(duì)停駛線前段的梯形區(qū)域進(jìn)行運(yùn)動(dòng)檢測(cè),檢測(cè)算法在PC機(jī)上運(yùn)行,通過(guò)串口將檢測(cè)結(jié)果及處理措施傳輸給單片機(jī),當(dāng)檢測(cè)出運(yùn)動(dòng)目標(biāo)時(shí)就認(rèn)為出現(xiàn)闖紅燈現(xiàn)象,啟動(dòng)報(bào)警燈,否則不啟動(dòng)。 然后用BuildCommDCB( )和SetCommState( )函數(shù)通過(guò)通信設(shè)備控制塊DCB(Device Control Block)設(shè)置串口通信參數(shù)(如波特率、停止位、數(shù)據(jù)位、校驗(yàn)位等),其中BuildCommDCB( )中的字符串參數(shù)lpDef 定義同DOS命令中MODE的參數(shù)格式,關(guān)于DCB更具體的設(shè)置需要根據(jù)用戶對(duì)數(shù)據(jù)流定義、握手信號(hào)及通信結(jié)論本系統(tǒng)采用美國(guó)ATMEL公司生產(chǎn)的單片機(jī)AT89c51,以及其它芯片(如:74HC16MX2374LS04六位反向器、L7805三端穩(wěn)壓電源)來(lái)設(shè)計(jì)交通燈控制器,實(shí)現(xiàn)了紅燈亮40秒,綠燈和左轉(zhuǎn)綠燈各亮20秒。 其中參數(shù)lpFileName指向串口邏輯名,如“COM1”或“COM2”等,參數(shù)dwDesiredAccess定義文件的讀寫權(quán)限,一般設(shè)為GENERIC—READ|GENERIC—WRITE;參數(shù)dwShareMode定義資源共享方式,此處必須設(shè)為0,為獨(dú)占方式;lpSecurityAttributes定義安全屬性,Win 95下為NULL;dwCreationDistribution定義文件創(chuàng)建方式;dwFlagsAndAttributes定義文件屬性和標(biāo)記,設(shè)為0表示同步通訊,設(shè)為FILE—FLAG—OVERLAPPED,表示異步通信方式;hTemplateFile 指向一個(gè)模板文件的句柄,在 Windows 95下為NULL,一般設(shè)置為0。API中與串行通訊相關(guān)的函數(shù)約由20個(gè),主要可以用到的函數(shù)有CreateFile( )、GetCommState( )、WriteFile( )、ReadFile( )、CloseHandle( )等函數(shù)。 (8) PC機(jī)串行通信實(shí)現(xiàn) C++Builder ()并沒(méi)有提供串行通訊所需的相關(guān)組件,其實(shí)現(xiàn)方法也是通過(guò)WINDOW API函數(shù)來(lái)實(shí)現(xiàn)的。即單片機(jī)與PC機(jī)的“發(fā)送數(shù)據(jù)線(TXD)”與“接受數(shù)據(jù)線(RXD)”交叉連接,二者的地線 (GND)之接相連,其他線均不相連。、VB、C++Bilder或VC++進(jìn)行編寫,考慮到可操作性和實(shí)現(xiàn)的快捷性,本文采用Inprise 公司(原Borland公司)推出的C++Builder來(lái)實(shí)現(xiàn)PC機(jī)的串行通信程序編寫。在具體編程的時(shí)候,我們可以實(shí)現(xiàn)很多的功能。 (6) 單片機(jī)與PC機(jī)串行通信實(shí)現(xiàn)手段 由于PC機(jī)中集成了串行異步通信的可編程芯片8250,我們可以通過(guò)PC機(jī)的串行通信口COM1或COM2對(duì)它進(jìn)行控制,因而不需要再單獨(dú)做實(shí)驗(yàn)板。常用的電平轉(zhuǎn)換芯片為MAX2232,此芯片能實(shí)現(xiàn)以上兩種電平的相互轉(zhuǎn)換。由于單片機(jī)的輸入、輸出是TTL電平(+5V表示邏輯1,電平低于2V便不能被識(shí)別為邏輯1;0V表示邏輯0),TTL電平一般不能用于遠(yuǎn)距離傳輸,因?yàn)閭鬏斶^(guò)程中電平的衰減會(huì)使傳輸數(shù)據(jù)不準(zhǔn)確。因?yàn)椴ㄌ芈试礁撸瑢?duì)發(fā)送和接收時(shí)鐘信號(hào)頻率的一致性要求就越高。在串行通信中常用波特率來(lái)衡量通信速率的快慢,每秒鐘傳送一位就是一波特,一般異步通信波特率為110~9600KHZ。 (4) 串行通信的傳送速率 傳送速率用于說(shuō)明數(shù)據(jù)傳送的快慢。接收方通過(guò)不斷檢測(cè)數(shù)據(jù)線的狀態(tài)來(lái)完成數(shù)據(jù)的接收,只要發(fā)送率和接收檢測(cè)速率相同,即能準(zhǔn)確接收和發(fā)送數(shù)據(jù)。接收方不斷檢測(cè)傳輸線的電平狀態(tài),當(dāng)發(fā)現(xiàn)傳輸線由高電平變?yōu)榈碗娖綍r(shí)(起始位標(biāo)志位),即認(rèn)為有數(shù)據(jù)傳入,進(jìn)入接收狀態(tài),然后以相同的速率檢測(cè)傳輸線的電平狀態(tài),接收隨后送來(lái)的數(shù)據(jù)位,奇偶校驗(yàn)位和停止位。 (3) 串行通信的收發(fā)過(guò)程 發(fā)送方發(fā)送數(shù)據(jù)時(shí),通過(guò)發(fā)送低電平起始位開始一個(gè)字符的傳送,起始位之后便按特定的速率發(fā)送數(shù)據(jù)位(包括奇偶校驗(yàn)位),當(dāng)最后