Problem With Digital Timer!!

Discussion in 'Embedded Systems and Microcontrollers' started by Shear_Intelligence, Jul 16, 2013.

  1. Shear_Intelligence

    Thread Starter New Member

    Jun 10, 2012
    29
    0
    Hi There,

    I Tried to impliment digital timer using 8051, user pushed button to enter desired amount of delay and then presses start button, when user pushes start button the value in timer0 (which i configured as counter), is displayed decreasing and when the value becomes 0 the relay is switched off,
    the problem which i cannot sort out is that controller is counting values and displays them perfect but when it comes to display value in decreasing i dunno what happens and output becomes ambiguous.
    Please help, because my hommies don't consider me an engineer without repairing home appliances :(

    Code that i wrote for it

    Code ( (Unknown Language)):
    1.  
    2. SEG0 EQU 30H
    3. SEG1 EQU 31H
    4. SEG2 EQU 32H
    5. SEG3 EQU 33H
    6. BUTTON EQU P3.4
    7. SEGMENT7 EQU P2
    8. STOP EQU P1.0
    9. START EQU P1.1
    10. ORG 00H
    11. TIMER_SETUP:
    12.  
    13.     MOV TMOD, #00010110B ;; 8 BIT AUTO RELOAD TIMER 0 AS COUNTER TIMER 1 AS 16 BIT TIMER
    14.     MOV TH0, #0D
    15.  
    16. MAIN:
    17.     SETB TR0
    18.     SETB BUTTON
    19.     SETB STOP
    20.     SETB START
    21.     MOV SEG0, #00H
    22.     MOV SEG1, #00H
    23.     MOV SEG2, #00H
    24.     MOV SEG3, #00H
    25.     CALL DISPLAY
    26.    
    27. GET:
    28.     MOV A, TL0
    29.     CALL CONV
    30.     CALL DISPLAY
    31.     JNB START, GO
    32.     JNB TF0, GET
    33.     JMP MAIN
    34. GO:
    35.     CLR TR0
    36.     MOV A, TL0
    37. GOT:
    38.     DEC A
    39.     CALL CONV
    40.     CALL DISPLAY
    41.     CALL DELAY_1S
    42.     MOV B, A
    43.     DJNZ B, GOT
    44.    
    45. CONV:
    46.     MOV B, #10D
    47.     DIV AB
    48.     MOV SEG0, B
    49.     MOV B, #10D
    50.     DIV AB
    51.     MOV SEG1, B
    52.     MOV SEG2, A
    53. RET
    54.  
    55. DISPLAY:
    56.    
    57.     MOV A, SEG0
    58.     ANL A, #0FH
    59.     ORL A, #80H
    60.     MOV SEG0, A
    61.     MOV SEGMENT7,SEG0
    62.     CALL DELAY
    63.     MOV A, SEG1
    64.     ANL A, #0FH
    65.     ORL A, #40H
    66.     MOV SEGMENT7,A
    67.     CALL DELAY
    68.     MOV A, SEG2
    69.     ANL A, #0FH
    70.     ORL A, #20H
    71.     MOV SEGMENT7,A
    72.     CALL DELAY
    73.     MOV A, SEG3
    74.     ANL A, #0FH
    75.     ORL A, #10H
    76.     MOV SEGMENT7,A
    77.     CALL DELAY
    78.    
    79.  
    80.  
    81. RET
    82. DELAY_TIME:
    83.     MOV R2, TH0
    84. AGAIN_TIME:
    85.     CALL DELAY_1MIN
    86.     DJNZ R2, AGAIN_TIME
    87. DELAY_1MIN:
    88.     MOV R1, #60D
    89. AGAIN_1MIN:
    90.     CALL DELAY_1S
    91.     DJNZ R1, AGAIN_1MIN
    92. DELAY_1S:
    93.     MOV R0, #20D
    94. AGAIN_1S:
    95.     CALL DELAY_50MS
    96.     DJNZ R0, AGAIN_1S
    97.    
    98. DELAY_50MS:
    99.     MOV TL1, #0B0H
    100.     MOV TH1, #3CH
    101.     SETB TR1
    102. CHECK:
    103.     JNB TF1, CHECK
    104.     CLR TR1
    105.     CLR TF1
    106.     RET
    107.    
    108. DELAY:
    109.     MOV R4, 255
    110.     DJNZ R4, $
    111. RET
    112. END
    113.  
     
    Last edited by a moderator: Jul 16, 2013
  2. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    [deleted] sorry
     
    Last edited: Jul 16, 2013
  3. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    How are your buttons connected - how do you set the numbers on the LED? I know there is "start" & "stop" and "button" in your software. But I can see only one button.

    Why there is no comments on your software? You know it would take hours for others to understand what is going on in your software.... Have you tried to draw a simple flow chart for your codes so you can understand the program flow better?

    Allen
     
  4. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    There are some mistakes in your code.....

    see below

    Code ( (Unknown Language)):
    1. GET:
    2.     MOV A, TL0          ;GET T0
    3.     CALL CONV           ;CONVERT TO bcd
    4.     CALL DISPLAY            ;DISPLAY ON LED
    5.     JNB START, GO   ;GOTO GO IF START IS PRESEED
    6.     JNB TF0, GET
    7.     JMP MAIN
    8. GO:
    9.     CLR TR0             ;STOP T0 COUNTER
    10.     MOV A, TL0                  ;PUT VALUE IN ACC
    11. GOT:
    12.     DEC A                       ;A=A-1
    13.     CALL CONV           ;VALUE IN ACC IS DESTROYED IN SUBROUTINES
    14.     CALL DISPLAY            ;TRY TO SAVE A IN TEMP_A
    15.     CALL DELAY_1S
    16.     MOV B, A                    ;COMPARE TEMP_A INSTEAD OF B REG
    17.     DJNZ B, GOT         ;DJNZ TEMP_A,GOT HERE
    18.    
    19. TEMP_A  EQU  R7 ;NEW VAR TEMP_A IS CREATED AT THE BEGINNING.
    Allen
     
  5. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    I don't know how long your program is, but I bet that it takes more than 48 bytes (there's more than 48 lines for the code). I think the the first lines should be:
    SEG0 EQU 78H
    SEG1 EQU 79H
    SEG2 EQU 7AH
    SEG3 EQU 7BH
    ...
     
    absf likes this.
  6. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    The Display hardware and software are also having problems.....

    You display each of the 4 digits for 50mS totaling 200mS and go to rest for 1000mS. The display would flicker and 80% of the time only the MSD is displaying or may be nothing.

    Since your LED display is common anode, it would be better to use PNP transistors and use logic low to switch on the digit. Are you just simulating or did you build the actual hardware?

    Allen
     
  7. Shear_Intelligence

    Thread Starter New Member

    Jun 10, 2012
    29
    0
    Actually to be very honest i don't understand what does those lines mean seg0 to seg1, i mean my teacher once wrote on the board and i wrote it, now i was going through my notes then i read and wrote in my software.
     
  8. Shear_Intelligence

    Thread Starter New Member

    Jun 10, 2012
    29
    0
    i actually build the hardware but with 2803 ic and programmed but din work so i decided to simulate first, the problem with this logic is this that i want to display decreasing no with the delay of 1 sec, i mean firstly a becomes for example 12 then displayed and decreamented after and second displayed 11, i want to do this but can't do this, and as far as npn transistor concerns it has fast switching as compared to pnp that's why i used it and easy to calculate value of RB
     
  9. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    SEG0 - SEG3 are the variables for storing the 4 digits to be displayed. Each variable consists of 2 parts. The lower nibble is the number 0-9 which goes to the 7447 decoder and the upper nibble is used to control which one of the 4 transistors to be turned on. Each bit is corresponding to one transistor.

    When the variable is masked with ORL #80H then bit 7=Hi and bits 6-4 = Lo, this is the LSD (unit digit).
    ORL #40H bit 6 = Hi, bits 7,5,4,= Lo
    ORL #20H bit 5 = Hi, bits 7,6,4 = Lo
    ORL #10H bit 4 = Hi, bits 7,6,5,=Lo.....

    Allen
     
    Last edited: Jul 17, 2013
    Shear_Intelligence likes this.
  10. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    The reason ULN2803 doesn't work is because your digits are common anode and they need +V on the common pins. The ULN2803 only has collectors and bases coming out of the IC and all the emitters are common together and come out on one pin. That's why you can't use it. Using discrete npn transistors, you can connect the emitter to the anode of the LED and collector to +V and use logic high to conduct the transistor to supply +V to the common anode.

    I know how the circuit works now and I have your circuit in my proteus working. But sine this is homework, I can only give you help instead of revealing the answer. That would be against the rules of this forum.....

    Didn't you get enough help form the above to make your circuit working yet? Your major problem has already been pointed out at post #4.

    Allen
     
  11. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    What Allen forgot to say was that the hexadecimal number is the address location of the variable. If your program is longer than 30h bytes, then using "SEG0 EQU 30H" will have you writing data in the middle of your code. You'll be lucky if your code still functions afterwards. Hopefully, using 78H (instead of 30H) will put the data after your program.
     
    Shear_Intelligence likes this.
  12. ananthapriya

    New Member

    Jul 18, 2013
    10
    3
    your button operation is manually or by software.you have tried to choose counter ah! yeah oh.this is possible we can use 8051 act as a counter also.you need to enable the counter operation you must choose C/T with bar. here choose this bit 1 is for counter operation if you need to enable time set this bit 0 ( this bit is available in Tmod Register) This is used for only if u have to choose counter opertion for 8051)



    BacklinksVault
     
    Last edited: Jul 25, 2013
    Shear_Intelligence likes this.
  13. Shear_Intelligence

    Thread Starter New Member

    Jun 10, 2012
    29
    0
    Sir, i'm done with my software when i simulate it, it works fine but when i burn it to hardware it works for 1 min and after a min first two digits are turned off, dunno why :( , and this isn't my home work if you have any idea please reveal that why digits are turned off circuit is same as attachment
     
  14. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    I am not sure what happens that it doesn't work in your hardware......It could be a hardware problem. Are you using the exact same 7-segment LED display and 7447 as in the simulator? Could it be a connection problem. Are your transistors tested before you use them? Was the circuit on breadboard or PCB?

    The only software problem that would make the first 2 digits not displaying is the CONV and DISPLAY subroutines. Try showing us your latest program and highlight those that you have changed compared to the one listed in post #1.

    Allen
     
    Shear_Intelligence likes this.
Loading...