装配增量计数器

时间:2017-10-29 19:11:03

标签: assembly 8051

我正在尝试使计数器增加1,从0开始,并使用LED显示0-15的二进制值,然后重置自身。我一直在第106,108,110和112行的KEIL软件中遇到错误A51。解决这些错误的任何帮助都会很棒。提前谢谢!

以下是代码:

#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

1 个答案:

答案 0 :(得分:1)

你没有指明你得到的错误。

JB x,1将跳转到命令的中间。无论如何,这里更容易指定标签。

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

等。