【正文】
E9: //主機(jī)請(qǐng)求設(shè)備狀態(tài) while(CLK==0||DAT==0)。 sendbyte(0xfa)。 while(CLK==0||DAT==0)。 sendbyte(0x12)。 while(CLK==0||DAT==0)。 sendbyte(0x03)。 while(CLK==0||DAT==0)。 sendbyte(0x3C)。 break。 default: //其他命令 while(CLK==0||DAT==0)。 sendbyte(0xfa)。 break。 } return 0。}void main(){ init_serial()。 //初始化串口 rcv_b_bit=0。 while(1) { //檢測(cè)下游主機(jī)是否要發(fā)送命令 if(CLK==0) { t=0。 //循環(huán)計(jì)時(shí)器清零 while(CLK==0) { delay8us()。 t++。 if(t20) //超時(shí)則該主機(jī)一直通信, goto d1。 if(DAT==0) { t=0。 while(CLK==0) { delay8us()。 t++。 if(t20) //超時(shí)則該主機(jī)一直通信, goto d1。 } rcv()。 t=0。 } } }d1: if(cansend==1) //若不是初始化狀態(tài),就要發(fā)送隊(duì)列中的數(shù)據(jù)報(bào) { if(FIFO_DL_N0) //若隊(duì)列中有未轉(zhuǎn)發(fā)的數(shù)據(jù)報(bào),就轉(zhuǎn)發(fā)一個(gè) { zhuanfa()。 } }}}void ReceiveData(void) interrupt 4{ char r。 RI=0。 r=SBUF。 //讀串口緩存數(shù)據(jù) if(FIFO_DL_L%4==0)//將隊(duì)列劃分為四字節(jié)八個(gè)區(qū)域到區(qū)域開頭就檢查報(bào)頭 { if((ramp。0xF8)!=0x50) //如果報(bào)頭格式錯(cuò)誤就丟棄 goto end。 } FIFO_DL[FIFO_DL_L++]=r。 //入隊(duì) if(FIFO_DL_L==32) //循環(huán)隊(duì)列 FIFO_DL_L=0。 FIFO_DL_byte++。 if(FIFO_DL_byte==4) //如果接收夠四個(gè)字節(jié) { FIFO_DL_byte=0。 FIFO_DL_N++。 //隊(duì)列內(nèi)的包數(shù)加一 if(FIFO_DL_N8) //若隊(duì)列溢出,丟掉隊(duì)列頭上的包 { FIFO_DL_H=(FIFO_DL_H+4)%32。 FIFO_DL_N=8。 } }end:}指導(dǎo)老師評(píng)語該設(shè)計(jì)應(yīng)用單片機(jī)模擬PS/2時(shí)序,不僅實(shí)現(xiàn)單片機(jī)模擬鼠標(biāo)與PC的通信,而且對(duì)題目進(jìn)行了擴(kuò)展,完成了串口信號(hào)向PS/2信號(hào)的轉(zhuǎn)換。經(jīng)過大量科學(xué)合理的測(cè)試,該系統(tǒng)性能可靠,與不同主板的PC的兼容性良好,具有一定的應(yīng)用價(jià)值。論該生能夠理論聯(lián)系實(shí)際,并進(jìn)行一定的創(chuàng)新,在畢業(yè)設(shè)計(jì)期間,工作量飽滿,查閱了多種資料,做了大量的測(cè)試實(shí)驗(yàn),表現(xiàn)出較強(qiáng)的分析問題和解決問題的能力。論文格式規(guī)范,結(jié)構(gòu)條例清晰,語言流暢。Implementation of MCU Input DeviceBased on PS / 2 mouse interfaceAbstract:PS/2 interface is an earlier puter interface, and it is also one of the most widely used interfaces. It is mainly applied to the input of the mouse, keyboard and game joysticks. PS/2 is a concise interface protocol which is easy to realize. Also, PS/2 equipments have a stable operation performance for many years. It is these advantages that make the ancient PS/2 interfaces have an important role in the field of input interface. Based on detailed analysis, this topic puts forward a set of feasible program which aims to realize PS/2 mouse interface device. The program provides a realization method of a PS/2 mouse interface device39。s hardware and software. This topic underlines those contents about the implement method of PS/2 interface drive, the work process of PS/2 mouse39。s reset model and stream model, and so on. According to the above solution, I make a PS/2 mouse interface device. This topic provides two basic function testing, two performance testing and a patibility testing for the device. The device obtains an ideal result in the testing. Finally I extend PS/2 mouse interface device and I switch serial port to PS/2 mouse device. This device39。s realization proves that the PS/2 mouse interface device which is realized in this topic have a favorable expandability.Key Words: PS/2 interface。Communication protocol。SCM。Mouse。Driver