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
also, over the entru window, if you looked, you would see how to place source code.
I second Pers comments re comments H3: MOV R4, #242 ;put 242 in R4 does not say squat, and where a comment would be useful, there is none.
general re comments
actually you con, in most cases 'comment' in two ways a) a comments and b) meaningful lables
e.g.
typedef enum { ALL_LEDS_OFF = 0xFF ... ... }t_led_bits
and #define Po LED-PORT
then
mov LED_PORT,#ALL_LEDS_OFF
is self commenting
do not fall for the fallacy that C is self commenting,that is only true with meaningful lables
No language is self-commenting.
The language and symbols may help tell a story of what is done. But it can't tell why it is done.
HERE: JNB A, HERE ;
Very unlikely that this is what you want.
JNB if Jump If Not Bit.
A is NOT a bit. It's the ACC register.
It will assemble, but do you want to really test the bit that has the address of ACC?
View all questions in Keil forum