實習四            兩開關控制一燈

   

實習目的:可任別處控制電燈

使用材料:

                    單晶片8051,1個

                    LED,8個

                    排線二條

                    開關二個

 流程圖:

電路圖:

 

程式:

                NEXT_CHECK:

                                                JB    P2.0         N0_KEY

                                                JMP         LAMP_OFF

                NO_KEY:

                                                JB    P2.1         NEXT_CHECK

                LAMP_ON:

                                                ANL        A.#01111111B

                                                MOV       P1.A

                                                SJMP       NEXT_CHECK

                LAMP_OFF:          

                                                ORL        A.#10000000B

                                                MOV       P1.A

                                                SJMP       NEXT_CHECK

                                                END

說明:

      第一行按P2.0則亮

                        第二行按P2.1則滅