基于單片機的紅外門進控制系統設計與制作:我們所做的創新實驗項目“基于單片機的紅外門控系統”已基本完成,現將其工作原理簡要說明。該系統主要分為兩大部分:一是紅外傳感器部分。二是單片機計數顯示控制部分?;倦娐穲D如下:其中紅外傳感器部分我們采用紅外對管實現,紅外對管平行放置,平常處于接收狀態,經比較器輸出低電平,當有人經過時,紅外線被擋住,接收管接收不到紅外線,經比較器輸出高電平。這樣,當有人經過時便會產生一個電平的跳變。單片機控制部分主要是通過外部兩個中斷判斷是否有人經過,如果有人經過,由于電平跳變的產生,進入中斷服務程序,這里我們采用了兩對紅外傳感器接到兩個外部中斷口,中斷0作為入口,實現加1操作,中斷1作為出口,實現減1操作。另外,我們通過P0口控制室內燈的亮暗,當寄存器計數值為0時,熄燈,不為0時,燈亮。顯示部分,采用兩位數碼管動態顯示,如有必要,可以很方便的擴展為四位計數。精益求精!在實驗過程中,我們走了非常多的彎路,做出來的東西根本不是自己想要的,我們本想做成室內只有一個門的進出計數,原理已清楚,即在門的兩邊放置兩對紅外對管,進出時,擋住兩對對管的順序不同,因此,可判斷是進入還是出去,從而實現加減計數,編程時,可分別在兩個中斷服務程序的入口置標志位,根據標志位判斷進出,詳細內容在程序部分。理論如此,但在實際過程中,還是發現實現不了上述功能,我們初步判定認為是程序掌握得不夠好,相信隨著自己對單片機了解的深入,應該會做出更好的 (因為我們是臨時學的單片機),程序的具體內容如下:
$MOD52 ORG 0000H LJMP Main ORG 0003H LJMP 0100H ORG 0013H LJMP 0150H ORG 0050HMain: CLR A MOV 30H , A ;初始化緩存區 MOV 31H , A MOV 32H , A MOV 33H , A MOV R6 , A MOV R7 , A SETB EA SETB EX0 SETB EX1 SETB IT0 SETB IT1 SETB PX1NEXT1: ACALL HEXTOBCDD ;調用數制轉換子程序 ACALL DISPLAY ;調用顯示子程序 LJMP NEXT1
ORG 0100H ;中斷0服務程序 LCALL DELY mov 70h,#2 djnz 70h,next JBC F0,NEXT SETB F0 CLR P0.0 LCALL DELY0 SETB P0.0 MOV A , R7 ADD A , #1 MOV R7, A MOV A , R6 ADDC A , #0 MOV R6 , A CJNE R6 , #07H , NEXT CLR A MOV R6 , A MOV R7 , ANEXT: RETI ORG 0150H ;中斷1服務程序 LCALL DELY mov 70h,#2 djnz 70h,next2 JBC F0,NEXT2 SETB F0 CLR P0.0 LCALL DELY0 SETB P0.0 CLR C MOV A , R7 SUBB A , #1 MOV R7, A MOV A , R6 SUBB A , #0 MOV R6 , A CJNE R6 , #07H , NEXT2 CLR A MOV R6 , A MOV R7 , ANEXT2: RETI
ORG 0200HHEXTOBCDD:MOV A , R6 ;由十六進制轉化為十進制 PUSH ACC MOV A , R7 PUSH ACC MOV A , R2 PUSH ACC CLR A MOV R3 , A MOV R4 , A MOV R5 , A MOV R2 , #10HHB3: MOV A , R7 ;將十六進制中最高位移入進位位中 RLC A MOV R7 , A MOV A , R6 RLC A MOV R6 , A MOV A , R5 ;每位數加上本身相當于將這個數乘以2 ADDC A , R5 DA A MOV R5 , A MOV A , R4 ADDC A , R4 DA A ;十進制調整 MOV R4 , A MOV A , R3 ADDC A , R3 DJNZ R2 , HB3 POP ACC MOV R2 , A POP ACC MOV R7 , A POP ACC MOV R6 , A RET ORG 0250HDISPLAY:
MOV R0 , #30H MOV A , R5 ANL A , #0FH MOV @R0 , A MOV A , R5 SWAP A ANL A , #0FH INC R0 MOV @R0 , A MOV A , R4 ANL A , #0FH INC R0 MOV @R0 , A MOV A , R4 SWAP A ANL A , #0FH INC R0 MOV @R0 , A MOV R0 , #30H MOV R2 , #11111110BAGAIN: MOV A , R2 MOV P2 , A MOV A , @R0 MOV DPTR , #TAB MOVC A , @A+DPTR MOV P1 , A ACALL DELAY INC R0 MOV A , R2 RL A MOV R2 , A JB ACC.4 , AGAIN
RETTAB: DB 03FH , 06H , 5BH , 4FH , 66H , 6DH , 7DH , 07H , 7FH , 6FH ;七段碼表DELY: MOV R1,#80D1: MOV R2,#100 DJNZ R2,$ DJNZ R1,D1 RET DELAY: MOV TMOD , #01H ;延時子程序 MOV TL0 , #0FEH MOV TH0 , #0FEH SETB TR0WAIT: JNB TF0 , WAIT CLR TF0 CLR TR0 RETDELY0: MOV R1, #200D3: MOV R2,#250 DJNZ R2,$ DJNZ R1,D3 RET END 該系統實際應用廣泛。可用在生產線上產品數量統計、公交車智能計數問候(需添加語音芯片)、超市內人數統計等公共場合。另外,添加串口通信部分便可實現與PC數據交換的功能。 由于,實驗簡化了,剩下不少零件和資金,所以我們又做了兩項其他的實驗。
標簽:
單片機
紅外
控制系統設計
原理圖
上傳時間:
2013-12-22
上傳用戶:tangsiyun
The μPSD32xx family, from ST, consists of Flash programmable system devices with a 8032 MicrocontrollerCore. Of these, the μPSD3234A and μPSD3254A are notable for having a complete implementationof the USB hardware directly on the chip, complying with the Universal Serial Bus Specification, Revision1.1.This application note describes a demonstration program that has been written for the DK3200 hardwaredemonstration kit (incorporating a μPSD3234A device). It gives the user an idea of how simple it is to workwith the device, using the HID class as a ready-made device driver for the USB connection.IN-APPLICATION-PROGRAMMING (IAP) AND IN-SYSTEM-PROGRAMMING (ISP)Since the μPSD contains two independent Flash memory arrays, the Micro Controller Unit (MCU) can executecode from one memory while erasing and programming the other. Product firmware updates in thefield can be reliably performed over any communication channel (such as CAN, Ethernet, UART, J1850)using this unique architecture. For In-Application-Programming (IAP), all code is updated through theMCU. The Main advantage for the user is that the firmware can be updated remotely. The target applicationruns and takes care on its own program code and data memory.IAP is not the only method to program the firmware in μPSD devices. They can also be programmed usingIn-System-Programming (ISP). A IEEE1149.1-compliant JTAG interface is included on the μPSD. Withthis, the entire device can be rapidly programmed while soldered to the circuit board (Main Flash memory,Secondary Boot Flash memory, the PLD, and all configuration areas). This requires no MCU participation.The MCU is completely bypassed. So, the μPSD can be programmed or reprogrammed any time, anywhere, even when completely uncommitted.Both methods take place with the device in its normal hardware environment, soldered to a printed circuitboard. The IAP method cannot be used without previous use of ISP, because IAP utilizes a small amountof resident code to receive the service commands, and to perform the desired operations.
標簽:
Demonstration
3200
USB
for
上傳時間:
2014-02-27
上傳用戶:zhangzhenyu