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

Fire Alarm Code Help

Discussion in 'Homework Help' started by CoolStuffZone, May 15, 2016.

  1. CoolStuffZone

    CoolStuffZone New Member

    Joined:
    May 15, 2016
    Messages:
    3
    Likes:
    0
    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 any assistance. Thank you.

    Code (asm):

    ORG 0H

      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
    H3:  MOV R4, #242
    H2:  MOV R3, #255
    H1:  DJNZ R3, H1
      DJNZ R4, H2
      DJNZ R5, H3
      RET

    END
     
     
    Last edited by a moderator: May 16, 2016
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,160
    Likes:
    909
    Location:
    Rochdale UK
    You are very nearly there..

    Looks like P1 is input and P2 is output..

    There is a SWAP command so P2 = 0x0F so you can swap it to oxF0!! very easy!

    My Rendition!!

    Code (ASM):

    STSWAP   EQU   30H     ; Holds LED condition

       ORG   0H
       SJMP   START     ; Always make room

    START:   MOV   A,#0     ; P2 output
       MOV   P2,A
       MOV   A,#0FFH     ; P1 input
       MOV   P1,A
       MOV   A,#0FH     ;
       MOV   STSWAP,A   ; Set first LED condition
    MAIN:   MOV   A,P1     ; Check switches
       CLR   C     ; Clear carry BEFORE sub
       SUBB   A,#255     ; If all switches OK it will be zero
       JNZ   ON
       MOV   A,#18H     ; Not in alarm
       MOV   P2,A     ; Display
       SJMP   MAIN     ; Go again..
    ON:   MOV   A,STSWAP   ; In alarm
       MOV   P2,A     ; Display
       SWAP   A     ; Change LED condition for next sweep
       MOV   STSWAP,A
       CALL   SDELAY     ; Wait to view
       JMP   MAIN     ; Go again..
       
    DELAY:   MOV   R3,#15
    OUTER:   MOV   R2,#240
    INNER:   DJNZ   R2,INNER
       DJNZ   R3,OUTER
       RET

    SDELAY:   MOV   R5,#5
    H3:   MOV   R4,#242
    H2:   MOV   R3,#255
    H1:   DJNZ   R3,H1
       DJNZ   R4,H2
       DJNZ   R5,H3
       RET

    END
     
     
  3. CoolStuffZone

    CoolStuffZone New Member

    Joined:
    May 15, 2016
    Messages:
    3
    Likes:
    0
    Thanks for the help. Will try the code tomorrow night in class. Will get back to you...
    Thanks again.

    Sincerely,
    Renick Marsh
     
  4. dave

    Dave New Member

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


     
  5. Kerim

    Kerim Member

    Joined:
    Nov 2, 2011
    Messages:
    64
    Likes:
    6
    Location:
    Aleppo city - Syria

    I wonder if the I/O pins of the C51 MCU are open-collector (as of the MCUs I have).
    In this case, the LEDs are usually connected (via current-limiting resistors) to Vcc of the MCU. Therefore, an LED could be turned on by setting its corresponding output at low level (0).

    Kerim
     
  6. CoolStuffZone

    CoolStuffZone New Member

    Joined:
    May 15, 2016
    Messages:
    3
    Likes:
    0
    Thanks again for all the help. The above code did work. The following is the code the instructor came up with...

    ORG 0
    MOV A, #0
    MOV P2, A
    MOV A, #0FFH
    MOV P1, A
    CLR A,

    BACK:
    MOV A, P1
    JB P1.1, FIRE
    MOV P2, #18H
    SJMP BACK

    FIRE:
    MOV P2, #15
    ACALL SDELAY
    MOV P2, #240
    ACALL SDELAY
    SJMP BACK

    DELAY:
    MOV R5, #45
    H3: MOV R4, #242
    H2: MOV R3, #255
    H1: DJNZ R3, H1
    DJNZ R4, H2
    DJNZ R5, H3
    RET

    END
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,160
    Likes:
    909
    Location:
    Rochdale UK
    For an instructor he isn't showing you forethought!!

    Org 0...... Its never wise to start programming here... When you start using vectors you will need to shift your program on... That why I always jump to start!! Then If I need a vector, I just pop it in!

    Also if The whole of P1 is an input then testing the first bit won't help!!
     

Share This Page