1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

the increment start from 00 to 99 continuously

Discussion in '8051/8951' started by nikzhafran, Feb 19, 2015.

  1. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    [​IMG]
    By following the schematic diagram,make a circuit for increment the number when each time the pattern button is pressed.
    An evaluation are including the :

    1)Tidiness
    2)Capabilities functioning according the increment start from 00 to 99 continuously.
    3)The gape of counting number should be 1 second


    can anyone help me how to make program in Code (asm) using keil AT89c51 ?

    Link deleted.......
     
    Last edited by a moderator: Feb 20, 2015
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    • Thanks Thanks x 1
  3. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    This code i do ..It is ok ?
    sorry because i new study about this

    Code (text):
            Org    00H

            data_one        equ    P3
            data_ten    equ    P2
     
            Mynumber        equ    30H  

    main_prog:    MOV    P2,#0C0H
            MOV    P2,#0c0H
            mov    Mynumber,#0
            JNB    P1.0,up_A
            JNB    P1.1,stop_A
            sjmp    main_prog  

    up_A:        mov    a, Mynumber
            Cjne    A,#99, up
            mov    Mynumber,#0FFH
            sjmp    up
         
    stop_A:        mov    a, Mynumber
            Cjne    A,#0, stop
            mov    Mynumber,#99H
            sjmp    stop

    up:        inc     Mynumber        
            JNB    P1.1,stop
            Call    BCD
            call    delay
            mov    a, Mynumber
            Cjne    A,#99, up
            mov    Mynumber,#0FFH        
            SJMP    up      

    stop:     dec     Mynumber        
            JNB    P1.0,up
            Call    BCD
            call    delay
            mov    a, Mynumber
            Cjne    A,#00, stop        
            mov    Mynumber,#100        
            SJMP    stop  
         
    BCD:        Mov     A,Mynumber
            Mov     B,#10
            Div    AB            
            call    Seg_conv
            mov    data_ten, A    
            mov    A,B
            call    Seg_conv
            mov    data_one, A    
            Ret

    Seg_conv:    inc     A
            Movc    A, @A+PC
            RET
         
            DB    0C0H    ; 0
            DB    0F9H    ; 1
            DB    0A4H    ; 2
            DB    0B0H    ; 3
            DB    099H    ; 4
            DB    092H    ; 5
            DB    082H    ; 6
            DB    0F8H    ; 7
            DB    080H    ; 8
            DB    090H    ; 9

    delay:        MOV    R5,#0ffh
            MOV    R6,#0ffH
            MOV    R7,#2
    delay_loop:    DJNZ    R5,delay_loop
            DJNZ    R6,delay_loop
            DJNZ    R7,delay_loop
            RET
         
            END  
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK

    Excellent first try...

    I have run the program and it works as expected.... When stop is released the counter counts up and when pattern is released it counts backwards..

    What next!!
     
    • Thanks Thanks x 1
  6. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    hi3 thank Ian Rogers .....
    i very happy ....hu3
    but i don't know how to stop it at that number if we push stop button it stop ...

    are we use

    stop:
    JNB P1.0,up ;jump p1.0 = 0
    SJMP stop


    It is ok for me to use this pushbutton or what of kind pushbutton i have to use
    [​IMG]
     
    • Like Like x 1
  7. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    when i test it doesn't work ? it 0 from the start and when push pattern and stop it not work...




    [​IMG]
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    First off... The micro hasn't got very good current driving or current sourcing capability... I would buffer them... I would also feed the LED's with 5v directly and put 1.2k resistors between every LED pin and micro pin... That would give you 2.5mA per pin...

    I will have to redo my circuit as I did it at work yesturday.. I'll post later.. Now Shopping ( Yuch!!)
     
    • Thanks Thanks x 1
  9. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    It seems your port 1 is not detecting your buttons. When no button is pushed, they should be logic low as you have R5 and R6 pulling it low. I changed you schematic a little bit, but there are some more problems that you have to take care of later.

    00-99 89c51 counting.PNG

    There are also problems in your software.

    Code (asm):
    main_prog:    MOV    P2,#0C0H
            MOV    P2,#0c0H
            mov    Mynumber,#0
            JNB    P1.0,up_A
            JNB    P1.1,stop_A
            sjmp    main_prog
     
    Your main_prog is a permanent loop. The 2 JNB after completed their tasks never return to the main_prog and just wandering in their subroutines. This is one of the causes why your program is not working.

    I did a little tuning on your code and it looks like it is working better but I dont know if that's the way you wanted it.....

    Code (asm):
            Org    00H

            data_one    equ    P3
            data_ten    equ    P2

            Mynumber    Equ    30H

    main_prog:  
        MOV    data_ten,#0C0H
            MOV    data_one,#0c0H
            mov    Mynumber,#0
            mov    p1,#0        ;set port 1 as input
            JB     P1.0,up_A
            JB     P1.1,stop_A
            sjmp    main_prog

    up_A:   mov    a, Mynumber
            Cjne    A,#99, up
            mov    Mynumber,#0FFH
            sjmp    up
       
    stop_A: mov    a, Mynumber
            Cjne    A,#0, stop
            mov    Mynumber,#99H
            sjmp    stop

    up:     inc     Mynumber      
            JB    P1.1,stop
            Call    BCD
            call    delay
            mov    a, Mynumber
            Cjne    A,#99, up
            mov    Mynumber,#0FFH      
            SJMP    main_prog    

    stop:   dec     Mynumber      
            JB    P1.0,up
            Call    BCD
            call    delay
            mov    a, Mynumber
            Cjne    A,#00, stop      
            mov    Mynumber,#100      
            SJMP    main_prog
       
    BCD:    Mov     A,Mynumber
            Mov     B,#10
            Div    AB          
            call    Seg_conv
            mov    data_ten, A  
            mov    A,B
            call    Seg_conv
            mov    data_one, A  
            Ret

    Seg_conv:    inc     A
            Movc    A, @A+PC
            RET
       
            DB    0C0H    ; 0
            DB    0F9H    ; 1
            DB    0A4H    ; 2
            DB    0B0H    ; 3
            DB    099H    ; 4
            DB    092H    ; 5
            DB    082H    ; 6
            DB    0F8H    ; 7
            DB    080H    ; 8
            DB    090H    ; 9

    delay:  MOV    R5,#0ffh
            MOV    R6,#0ffH
            MOV    R7,#2
    delay_loop:    DJNZ    R5,delay_loop
            DJNZ    R6,delay_loop
            DJNZ    R7,delay_loop
            RET
       
            END
    Allen
     
    • Thanks Thanks x 1
  10. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Although the simulator won't care, you do need 0.1uF decoupling caps on the CPU.

    Your displays should not use a common current limiting resistor but one for each segment. With a 5V supply 330 ohm is typical.
     
    • Thanks Thanks x 1
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Oooh! Port1 will be an out put if you write 0x00 to it..

    The easiest way to interface to a micro is normally high, pulled low... and change software to suit!!

    Also this line mov Mynumber,#99H Is a tad too high for the BCD convertor...
     
    • Thanks Thanks x 2
  12. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    Thank You Ian Rogers ,absf and blueroomelectronics
    i have learn many thing today.....
    i will do this and if anything probleam i will ask....

    set port 1 as input that mean output
    that mean put #0 ?

    #sorry for my poor english
     
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    The latch on the port of the humble 51 is designed in a way that if a 1 is written to the port pin, the output fet will be off and the port pin goes high.... That means that if a 0 is written to the port pin the fet will be on and a short to ground exists.. If you send a logic 1 into the port pin whilst it's latch is low, there will be magic smoke...
     
    • Thanks Thanks x 1
  14. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    hi3 ok2 i understand if 1 it high and 0 is low

    Now ,This code if i click stop it will dicrement ..
    How to program when i click pushbotton stop it will reset ...


    should i delete dec or change some code

    like mov mynumber,#00h



    stop:
    JNB P1.0,up ;jump p1.0 = 0
    SJMP stop
     
  15. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    reset i mean back to 00
     
  16. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    You are absolutely right, Ian. I read the HW manual again, and yes it needs logic H to set the port as input and Logic Low as output.

    8051 port direction.PNG

    So the circuit has to be changed to detect a LOW input instead of High. I will modify the circuit and post the corrected one again.

    Allen
     
    • Like Like x 1
  17. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    This program when i push the button it increment directly 00 to 99 ... .....
    How to make program when each time pattern press it incress one by one ( number 0 then we press pattern it will 1 and press again it be 2 ,press again it be 3 and to 99 )
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I use a keylock.... Wait for a keypress!! Delay 20mS Wait for key release...
     
    • Thanks Thanks x 1
  19. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    I hope I have the circuit correct this time...

    00-99 89c51 counting 2.PNG

    Change all "JB" to "JNB" in order to detect a low pressed button.

    Allen
     
    • Agree Agree x 1
  20. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Looks good.
     
    • Thanks Thanks x 2
  21. nikzhafran

    nikzhafran New Member

    Joined:
    Feb 19, 2015
    Messages:
    10
    Likes:
    1
    code like this ?

    Org 00H

    data_one equ P3
    data_ten equ P2
    IPIN EQU P1.0
    DPIN EQU P1.1
    Mynumber Equ 30H

    main_prog:
    CALL INIT
    AGAIN:

    AG2: JB IPIN,AG1
    CALL DELAY1 ;debounce
    JB IPIN,AG1
    JNB IPIN,$ ;wait till switch release
    INC MYNUMBER
    mov a,mynumber
    cjne a,#100,pq1
    mov mynumber,#0
    pq1:
    call bcd ;diaplay data


    AG1: JB DPIN,AG2
    CALL DELAY1
    JB DPIN,AG2
    JNB DPIN,$
    dec mynumber
    mov a,mynumber
    cjne a,#255,pq2
    mov mynumber,#99
    pq2:
    call bcd
    JMP AGAIN


    INIT:
    MOV data_ten,#0C0H
    MOV data_one,#0c0H
    mov Mynumber,#0
    mov p1,#255 ;set port 1 as input BY . IT SHOULD BE 1
    RET

    DELAY1: MOV R4,#255
    DJNZ R4,$
    RET

    BCD: Mov A,Mynumber
    Mov B,#10
    Div AB

    movc dptr,#seg_conv
    MOVC A,@A+DPTR ; MOVE DATA @A+DPTR IN A
    mov data_ten, A

    mov A,B
    movc dptr,#seg_conv
    MOVC A,@A+DPTR ; MOVE DATA @A+DPTR IN A
    mov data_one, A
    Ret

    delay: MOV R5,#0ffh
    MOV R6,#0ffH
    MOV R7,#2
    delay_loop: DJNZ R5,delay_loop
    DJNZ R6,delay_loop
    DJNZ R7,delay_loop
    RET

    Seg_conv:
    DB 0C0H ; 0
    DB 0F9H ; 1
    DB 0A4H ; 2
    DB 0B0H ; 3
    DB 099H ; 4
    DB 092H ; 5
    DB 082H ; 6
    DB 0F8H ; 7
    DB 080H ; 8
    DB 090H ; 9

    END
     

Share This Page