⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coun2051.asm

📁 2051 based counter program. 5 Digit Display
💻 ASM
字号:
;***********************************************************************
;COUNTER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;***********************************************************************
;Chip: AT89C2051, Cystal: 24MHz,12 CLK
;***********************************************************************
;Programed by:  Engr. Shahid            
;                                               
;                               M/S Engineering Complex                       
;                               415, Lion Shopping Complex             
;                               73 Monipuripara, Airport Road          
;                               Tejgaon, Dhaka-1215, Bangladesh.       
;                               Ph: +880-2-9137453                     
;                               Fax:+880-2-9139563                    
;                               E-mail: ecl@dhaka.net                                   
;
;******************************************************
;Date of Development:   09/05/2004, Day: Sunday       *
;Date of Modification : 07/08/2006, Day: Monday       *
;Version: 1.10                                        *
;******************************************************
;
;Connection List:
;           U6/CD4514   U7/ULN2003  U8/ULN2003  H1      7-SEG.  Cathod
;==============================================================
;               S0/11           1-16            -                       21      DS0             K0 
;               S1/9            2-15            -                       22      DS1             K1
;               S2/10           3-14            -                       23      DS2             K2
;               S3/8            4-13            -                       24      DS3             K3
;               S4/7            5-12            -                       25      DS4             K4
;               S5/6            6-11            -                       26      DS5             K5
;               S6/5            7-10            -                       27      DS6             K6
;               S7/4            -                       1-16            14      DS7             K7
;               S8/18           -                       2-15            15      DS8             K8
;               S9/17           -                       3-14            16      DS9             K9
;               S10/20          -                       4-13            17      DS10    K10
;               S11/19          -                       5-12            18      DS11    K11
;               S12/14          -                       6-11            19      DS12    K12
;               S13/13          -                       7-10            20      DS13    K13
;               S14/16          -                       -       N/C
;               S15/15          -                       -   N/C
;
;               U3/89C52    H1
;===========================================================
;               P2.0/21     N/C    
;               P2.1/22     3 All LED Anode(Via R10 4K7,Q9/2N4403 PNP,
;                                                                       Collector to All LED Anode, Emitter to Vcc).
;               P2.2/23     5 All Switches(R9/4K7 Connected to Vcc from P2.2)
;               P2.3/24     CD4511/U5/Pin-3/^LT(Normally to be High).
;               P2.4/25     6 All dp's(Via R7/4K7, Q7/2N403,
;                                                          collector to All dp's Anode, Emitter to Vcc).
;               P2.5/26     U6/CD4514/Pin-1/Strobe
;               P2.6/27     CD4511/U5/Pin-5/LE(Low for On, High for OFF the SEGMENT).
;               P2.7/28     U4/DS12C885/Pin-13/^CS
;
;               P0.0/39     U5/CD4511/Pin-7 and U6/CD4514/Pin-2  A Input and U4/DS12C885/AD0/Pin-4 
;               P0.1/38     U5/CD4511/Pin-1 and U6/CD4514/Pin-3  B Input and U4/DS12C885/AD1/Pin-5
;               P0.2/37     U5/CD4511/Pin-2 and U6/CD4514/Pin-21 C Input and U4/DS12C885/AD2/Pin-6
;               P0.3/36     U5/CD4511/Pin-6 and U6/CD4514/Pin-22 D Input and U4/DS12C885/AD3/Pin-7
;
;               P0.4/35     U4/DS12C885/AD4/Pin-8
;               P0.5/34     U4/DS12C885/AD5/Pin-9
;               P0.6/33     U4/DS12C885/AD6/Pin-10
;               P0.7/32     U4/DS12C885/AD7/Pin-11
;               ALE/30      U4/DS12C885/AS /Pin- 14 
;               
;       CD4514 Output should be low for Segment Display,i.e: ULN Input High.


                $MOD51
                ORG 00H
                LJMP MAIN
                ;
MAIN:   MOV SP,#30H;Set SP to 30H
                ; 
START:  ;SETB P2.6 ;Pin 5 of CD4511 ^LE. for OFF the segment display.
                SETB P3.4 ;Pin 5 of CD4511 ^LE. for OFF the segment display.
                MOV 40H,#00H;Segment Zero Initial Data is 0FFH
                MOV 41H,#0FFH;Next Segment Initial Data is 0FFH  
                MOV 42H,#0FFH
                MOV 43H,#0FFH
                MOV 44H,#0FFH
                MOV 45H,#0FFH
                MOV 46H,#0FFH
                MOV 47H,#0FFH
                MOV 48H,#0FFH
                MOV 49H,#0FFH
                MOV 4AH,#0FFH
                MOV 4BH,#0FFH
                MOV 4CH,#0FFH
                MOV 4DH,#0FFH
        ;
        ;
        ;MOV 50H,#00H
        ;MOV 51H,#00H
        ;MOV 52H,#00H
        ;MOV 53H,#00H
        ;MOV 54H,#00H
        ;MOV 55H,#00H
        ;
        ;
                ;SETB P2.1 ; All LED OFF
                ;CLR  P2.2 ; All SW    
                ;SETB P2.3 ;CD4511/U5/Pin-3/^LT(Normally to be High).
                ;SETB P2.4 ; All dp's OFF
        ;CLR P2.4   
        ;
        MOV TMOD,#01100000B;Counter 1 is used as 8 Bit Auto-Reload. 
        MOV TH1,#0
        MOV TL1,#0
        SETB P3.5; Make(T1 Pin as Input).  
        SETB TR1 ; Start External Counter.
        ;       
DISP:   ACALL COUNT 
AGAIN:  MOV R0,#40H ;Segment ZERO data location is 40H.
        MOV R4,#0DH ;Segment ZERO Selection Byte.
BACK:   CJNE @R0,#0FFH,SEG      ;Check for the Segment to be OFF. 
                                                        ;If FFH Then Skip The segment.
        SJMP SEG1
SEG:    ;MOV P0,R4  ; Place Segment selction Byte to Port 0.
                MOV P1,R4  ; Place Segment selction Byte to Port 0.
                ;SETB P2.5 ;Strobe for CD4514 for Segment Selection. 
                SETB P3.7 ;Strobe for CD4514 for Segment Selection. 
                NOP
                CLR P3.7
                ;MOV P0,@R0;Transfer the Segment data to Port 0. 
                MOV P1,@R0;Transfer the Segment data to Port 0. 
                ;CLR  P2.6 ;Pin 5 of CD4511 ^LE. for ON the segment display.    
                ;SETB P2.6 ;Pin 5 of CD4511 ^LE. for OFF the segment display.
                CLR  P3.4 ;Pin 5 of CD4511 ^LE. for ON the segment display.     
                SETB P3.4 ;Pin 5 of CD4511 ^LE. for OFF the segment display.
                
SEG1:   ACALL DELAY ;Segment OFF Period.Standard Is 1mSec.Here 2mSec Used.  
                DEC R4      ;Next Segment Selection Byte in R4.
                INC R0      ;Next Segment data location in R0.
                CJNE R4,#08H,BACK;Return for next Segment Display. 
RE:             SJMP DISP  ;Continue Segment Display


                ORG 150H
COUNT:  MOV 40H,TL1 ;Load TL1 value to Segment ZERO Address.
                MOV A,40H 
                ANL A,#0FH;Unpack BCD the Counter value.
                CJNE A,#0AH,REP ;If Current Digit value don't cross Decimel 9
                                                ;then retrun without increasing the next digit.
                MOV TL1,#0      ;If Digit TL1 value crosses Decimal 9, then
                                                ;Digit ZERO is set to 0 and increase next Digit
                                                ;value.
                MOV 40H,#0
S1:             INC 41H
                ;
                MOV A,41H       ;Initial value is loaded FFH so first increase 
                                                ;will be 00, So another increament is required. 
                JZ S1
                CJNE A,#0AH,REP
                MOV TL1,#0
                MOV 40H,#0
                MOV 41H,#0
S2:             INC 42H
                ;
                MOV A,42H
                JZ S2
                CJNE A,#0AH,REP
                MOV TL1,#0
                MOV 40H,#0
                MOV 41H,#0
                MOV 42H,#0
S3:             INC 43H
                ;
                MOV A,43H
                JZ S3
                CJNE A,#0AH,REP
                MOV TL1,#0
                MOV 40H,#0
                MOV 41H,#0
                MOV 42H,#0
                MOV 43H,#0
S4:             INC 44H
                ;
                MOV A,44H
                JZ S4
                CJNE A,#0AH,REP
                MOV TL1,#0
                MOV 40H,#0
                MOV 41H,#0
                MOV 42H,#0
                MOV 43H,#0
                MOV 44H,#0
S5:             INC 45H
                ;
                MOV A,45H 
                JZ S5
                CJNE A,#0AH,REP
                MOV TL1,#0
                MOV 40H,#0FFH
                MOV 41H,#0FFH
                MOV 42H,#0FFH
                MOV 43H,#0FFH
                MOV 44H,#0FFH
                MOV 45H,#0FFH
REP:    RET
                
                ORG 300H
DELAY:  ;Dealy for 2 MSec. P89C51RD2BN & AT89C2051,24MHz Crystal,12 Clk Mode.
                MOV R2,#4
Loop1:  MOV R3,#250     ;1 Machine cycle 
Loop2:  NOP
                NOP
                DJNZ R3,Loop2
                DJNZ R2,Loop1
                RET             ;return to caller   
                END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -