urgent help to write a counter program using keil uvision assembly (AT89S52)

Discussion in 'Embedded Systems and Microcontrollers' started by lordnaikon, Jan 16, 2010.

  1. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    hi all

    Currently im doing a project for my final year. My project have two infrared sensor. Which i put sensor 1 at entrance and sensor 2 at the exit. I mean like visitor counter. I use atmel 8052 microcontroller (AT89S52) and i program it in assembly language. I program port 2 as sensor input,port 1 is output and port 3 as counter which give 8 bit binary code from P3.0 to P3.7. Im stuck with the counter part only. The others all ok. I want to display from 00 to 99. So,the 8 bit binary will display until 99. I already done with two common anode 7 segment display and two SN74LS47N ic which is BCD to 7 segment decoder. The display will display from 0 to F. In BCD,it just display 0 to 9 right? how do i skip from A to F? I mean,i just want to display 0 to 9 only. I also try using common cathode 7 segment with 74HC4511.The ic is the same with 74LS47. The result is the same. But when the counter reach 10 to 15. It will give blank display for A,B,C,D,E,F and come back to 0. so it will count until 15 too. Suppose after 9 it will display 0 and another one 7 segment will display 1. it will display 10 by using two 7 segment and it will count until 99. Can anyone please help me.. how do i skip A(1010),B (1011),C (1100),D (1101),E (1110), F (1111) and just displaying 0 to 9. Another things is how do i convert from binary to BCD? someone expert in assembly please help me. Sorry for my bad english.

    here is my program i wrote in keil μvision assembly.

    Code ( (Unknown Language)):
    1. ORG 0000H
    2. MOV P0,#0H
    3. MOV P1,#0H
    4. MOV P2,#0H
    5. MOV R3,#0H
    6.  
    7. MAIN:    JB P2.0, INCRES
    8.          JB P2.1, DECRES
    9.          SJMP MAIN
    10.  
    11. INCRES: INC R3
    12.         MOV P3,R3
    13.         ACALL  DELAY      
    14.         SJMP MAIN
    15.        
    16.  
    17. DECRES: DEC R3
    18.         MOV P3,R3
    19.         ACALL  DELAY  
    20.         SJMP MAIN
    21.  
    22.  
    23. DELAY:  MOV    R0,#20
    24. LOOP3:  MOV    R1,#255
    25. LOOP2:  MOV    R2,#255
    26. LOOP1:  DJNZ   R2,LOOP1
    27.         DJNZ   R1,LOOP2
    28.         DJNZ   R0,LOOP3
    29.        
    30.     RET    
    31.  
    32.     END
    please help me to convert from binary to bcd.

    thanks in advance.:)
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Try serching for AN526 on the Microchip site. It is a different processor with different assembler instructions but it explains the algorithm.
     
  3. go7aaaa

    New Member

    Apr 11, 2010
    1
    0
    INCLUDE 8051.mc
    ORG 0000H
    MOV P0,#0H
    MOV P1,#0H
    MOV P2,#0H
    MOV R3,#0H

    MAIN: JB P2.0, INCRES
    JB P2.1, DECRES
    SJMP MAIN

    INCRES: INC R3
    MOV A,R3
    DA A
    MOV P3,A
    ACALL DELAY
    SJMP MAIN


    DECRES: DEC R3
    MOV A,R3
    DA A
    MOV P3,A
    ACALL DELAY
    SJMP MAIN


    DELAY: MOV R0,#20
    LOOP3: MOV R1,#255
    LOOP2: MOV R2,#255
    LOOP1: DJNZ R2,LOOP1
    DJNZ R1,LOOP2
    DJNZ R0,LOOP3

    RET

    END
     
Loading...