Continue to Site

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.

  • 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.

the increment start from 00 to 99 continuously

Status
Not open for further replies.

nikzhafran

New Member
IMG_20150220_082546.jpg

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:
This code i do ..It is ok ?
sorry because i new study about this

Code:
        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
 
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_20150220_200544.jpg
 
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!!)
 
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:
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:
        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
 
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.
 
mov p1,#0 ;set port 1 as input
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...
 
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...
 
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 ...

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


stop: dec Mynumber
JB P1.0,up
Call BCD
call delay
mov a, Mynumber
Cjne A,#00, stop
mov Mynumber,#100
SJMP main_prog

should i delete dec or change some code

like mov mynumber,#00h



stop:
JNB P1.0,up ;jump p1.0 = 0
SJMP stop
 
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...

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
 
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 )
 
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
 
I hope I have the circuit correct this time...

View attachment 90969

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

Allen

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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top