This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Fire Alarm System Homework Help

Forum
Need help with the following Homework assignment…
Design a fire alarm system using a 8051 microcontroller. The specs are as follows:
A) If the alarm is detected (one of the switches is activated) it should start flashing 4 LEDS (4 on the right (LEDS 1-4) and 4 on the left (LEDS 5-8), alternating).
B) If the alarm is not detected, the display should show only 2 middle LEDS (LEDS 4 & 5) steadily ON (not flashing) indicating NORMAL operation.
This is the code I’ve come up with so far, but I appear to be stuck. I would appreciate and assistance. Thank you.

Code…

ORG 0H ;Program starting location MOV A, #0 ; MOV P2, A ; MOV A, #OFFH ; MOV P1, A ;

INPUT: MOV A, P1 ;

HERE: JNB A, HERE ; MOV P2, #1 ;

DELAY: MOV R3, #15 ;
OUTER: MOV R2, #240 ;
INNER: DJNZ R2, INNER ; DJNZ R3, OUTER ; RET

SDELAY: MOV R5, #45 ;put 45 in R5
H3: MOV R4, #242 ;put 242 in R4
H2: MOV R3, #255 ;put 255 in R5
H1: DJNZ R3, H1 ;Decrement R3 keep @ H1 if not zeroed DJNZ R4, H2 ;Decrement R4 keep @ H2 if not zeroed DJNZ R5, H3 ;Decrement R5 keep @ H3 if not zeroed RET ;Return & Go back to line after ACALL

;--------------------

END

Parents
  • 1) Why not use the proper formatting, as clearly explained directly above the message input box?

    2) Why not think carefully about what to comment and how to use labels and variables?

    MOV A, #0 ;
    MOV P2, A ;
    


    What would make a reader know if this is intended to clear any LED?

    MOV A, #OFFH ;
    MOV P1, A ;
    


    What would make a reader know if this is intended to make P1 into eight "input"?

    INPUT: MOV A, P1 ;
    


    What reader would know what is connected to P1 and what the values in A would then actually represent? And are all pins of P1 relevant?

    HERE: JNB A, HERE ;
    


    Hmm - how well do "here" explain this?
    And how do you expect to leave this loop?

    MOV P2, #1 ;
    


    What reader would know what the magic value #1 will actually control on that port?

    DELAY: MOV R3, #15 ;
    OUTER: MOV R2, #240 ;
    INNER: DJNZ R2, INNER ;
           DJNZ R3, OUTER ; RET
    


    What was your intention with "RET"?

    SDELAY: MOV R5, #45 ;put 45 in R5
    H3: MOV R4, #242 ;put 242 in R4
    H2: MOV R3, #255 ;put 255 in R5
    


    Suddenly you have started to write comments - but what value is a comment that tells the reader that yu put the value 45 into a register? Is the reader not expected to understand the assembler instructions?

    And what is the difference between the label DELAY and SDELAY - can that difference be understood by the label names?

    And do you think label names "H2" and "H3" really gives much help to a reader?
    And what was the actual meaning of all these numbers? Arbitrary numbers or intended to produce a specific result? You know it's possible to declare named constants in assembler?

    RET ;Return & Go back to line after ACALL
    


    So we suddenly have an ACALL?
    Where?
    And would the comment be correct if the caller decides on a LCALL instead?

    Remember that your task is to spend own time getting stuck. Reviewing. Rewriting. Getting stuck. Reviewing. Rewriting. Testing. Rreviewing. Rewriting. Testing.

    Rinse/repeat until you have a final solution that works. That's how you learn. Trying to short-circuit that process will not help you with the following assignments or when it's time for the final tests to pass the course.

Reply
  • 1) Why not use the proper formatting, as clearly explained directly above the message input box?

    2) Why not think carefully about what to comment and how to use labels and variables?

    MOV A, #0 ;
    MOV P2, A ;
    


    What would make a reader know if this is intended to clear any LED?

    MOV A, #OFFH ;
    MOV P1, A ;
    


    What would make a reader know if this is intended to make P1 into eight "input"?

    INPUT: MOV A, P1 ;
    


    What reader would know what is connected to P1 and what the values in A would then actually represent? And are all pins of P1 relevant?

    HERE: JNB A, HERE ;
    


    Hmm - how well do "here" explain this?
    And how do you expect to leave this loop?

    MOV P2, #1 ;
    


    What reader would know what the magic value #1 will actually control on that port?

    DELAY: MOV R3, #15 ;
    OUTER: MOV R2, #240 ;
    INNER: DJNZ R2, INNER ;
           DJNZ R3, OUTER ; RET
    


    What was your intention with "RET"?

    SDELAY: MOV R5, #45 ;put 45 in R5
    H3: MOV R4, #242 ;put 242 in R4
    H2: MOV R3, #255 ;put 255 in R5
    


    Suddenly you have started to write comments - but what value is a comment that tells the reader that yu put the value 45 into a register? Is the reader not expected to understand the assembler instructions?

    And what is the difference between the label DELAY and SDELAY - can that difference be understood by the label names?

    And do you think label names "H2" and "H3" really gives much help to a reader?
    And what was the actual meaning of all these numbers? Arbitrary numbers or intended to produce a specific result? You know it's possible to declare named constants in assembler?

    RET ;Return & Go back to line after ACALL
    


    So we suddenly have an ACALL?
    Where?
    And would the comment be correct if the caller decides on a LCALL instead?

    Remember that your task is to spend own time getting stuck. Reviewing. Rewriting. Getting stuck. Reviewing. Rewriting. Testing. Rreviewing. Rewriting. Testing.

    Rinse/repeat until you have a final solution that works. That's how you learn. Trying to short-circuit that process will not help you with the following assignments or when it's time for the final tests to pass the course.

Children
No data