NickH
NickH

Reputation: 1

Assembly increment counter

I am trying to make a counter that increments by 1, starting at 0, and uses LED's to show the value in binary from 0-15 then resets itself. I keep running into error A51 in KEIL software on lines 106, 108, 110, and 112. Any help in solving these errors would be great. Thank you in advance!

Here is the code:

#include <reg932.inc> 

cseg at 0           ;tells assembler to place 1st instruction in address 0

    MOV 0xA4, #0    ; set port 2 to bi-directional
    MOV 0x91, # 0   ; set port 1 to bi-directional 
    MOV 0x84, #0    ; set port 0 to bi-directional
    clr c 
    mov A, # 00     ; set accumulator to 0



;lights in a circle
MOV R4, #01         ; set R4 to 0 for 1 loop
MOV R5, #01         ; set R5 to 0 for 1 loop
MOV R6, #15     ; set R6 to 0 for 15 loop


LightsLoop:         ; will light up leds in a circle one at a time

    CPL P2.4
    ACALL LightsDelay
    CPL p2.4
    CPL p0.5
    ACALL LightsDelay
    CPL p0.5
    CPL p2.7
    ACALL LightsDelay
    CPL p2.7
    CPL p0.4
    ACALL LightsDelay
    CPL p0.4
    CPL p2.6
    ACALL LightsDelay
    CPL p2.6
    CPL p0.7
    ACALL LightsDelay
    CPL p0.7
    CPL p2.5
    ACALL LightsDelay
    CPL p2.5
    CPL p0.6
    ACALL LightsDelay
    CPL p0.6
    CPL p2.4
    ACALL LightsDelay
    CPL p2.4

    DJNZ R4, LightsLoop


LightsOnLoop:       ; will light up leds in a circle with them staying on

    CPL p2.4
    ACALL LightsDelay
    CPL p0.5
    ACALL LightsDelay
    CPL p2.7
    ACALL LightsDelay
    CPL p0.4
    ACALL LightsDelay
    CPL p2.6
    ACALL LightsDelay
    CPL p0.7
    ACALL LightsDelay
    CPL p2.5
    ACALL LightsDelay
    CPL p0.6
    ACALL LightsDelay
    CPL p0.6
    ACALL LightsDelay
    CPL p2.4
    DJNZ R5, LightsOnLoop
    SJMP START

LightsDelay:
    MOV R7, #30
    LOOP7:
        MOV R0, #250
        LOOP0:
            MOV R1, #250
                LOOP1:
                    DJNZ R1, LOOP1
    DJNZ R7, LOOP7
    RET

START:                      ;*****find out where this belongs*****
    MOV A, #00010000B
    ACALL Loop

Loop:
    CJNE A, #00000000B ,Next        
    ;mAKE A SOUND
    MOV A, #00010000B
    SJMP Loop

Next:
    DEC A
        JB P0.3, 1        ;ERROR LINE
            ACALL AmberPin
        JB P0.2, 1        ;ERROR LINE
            ACALL GreenPin
        JB P0.1, 1        ;ERROR LINE
            ACALL YellowPin
        JB P0.0, 1        ;ERROR LINE
            ACALL RedPin
    SJMP Loop


RedPin:
    CPL P2.4
    ACALL LightsDelay
    CPL p2.4
    SJMP Loop

AmberPin:
    CPL P0.6
    ACALL LightsDelay
    CPL p0.6
    SJMP Loop

GreenPin:
    CPL P2.7
    ACALL LightsDelay
    CPL p2.7
    SJMP Loop

YellowPin:
    CPL P0.5
    ACALL LightsDelay
    CPL p0.5
    SJMP Loop
END

Upvotes: 0

Views: 1852

Answers (1)

Ora
Ora

Reputation: 66

You did not specify what error you're getting.

JB x, 1 will jump into the middle of a command. In any case, it's easier to specify a label here.

        JB P0.3, NotAmber  
            ACALL AmberPin
NotAmber:
        JB P0.2, NotGreen

etc.

Upvotes: 1

Related Questions