實習二                  紅綠燈

實習目的:  瞭解如何使用8051來控制LED之亮滅,進而自做紅綠燈.

使用材料:  8051單晶片 

                    8個顯示用  

                    LED排組

功能說明:  使用8051來控制LED,達成製作紅綠燈的目的

 

程式流程圖:

電路圖:

程式及說明:

                                      ORG         0H

                    START      MOV        R3,#0

                                      MOV        DPTR,#TABLE

                     TT1           MOV        A,R3

                                      MOVC      A,@A+DPTR

                                      CALL       DELAY

                                       INC         R3

                                      CJNZ        R3,#35TT1

                                       JMP          START

                     DELAY     MOV        R2,#3                   

                     DD3           MOV       R1,#255

                     DD2           MOV       R0,#255

                     DD1           DJNZ       R0,DD1

                                        DJNZ       R1,DD2

                                        DJNZ       R2,DD3

                                        RET

                     TABLE            DB       11010111B

                                             DB       11010111B

                                             DB       11010111B                     

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11010111B

                                             DB       11110111B

                                             DB       11010111B

                                             DB       11110111B

                                             DB       11010111B

                                             DB       11110111B

                                             DB       10110111B

                                             DB       10110111B

                                             DB       10110111B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111101B

                                             DB       01111111B

                                             DB       01111101B

                                             DB       01111111B

                                             DB       01111101B

                                             DB       01111111B

                                             DB       01111011B    

                                             DB       01111011B   

                                             DB       01111011B