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

CoolStuffZone

New Member
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:
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:
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:
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
 
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
 
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
 
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!!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top