减少时DAW不起作用-组装

时间:2019-03-11 13:06:56

标签: assembly pic

我是第一次将其用于单片机PIC18F458。我被要求在单位和十个7段上显示从99到00的计数序列。

我使用以下代码,但DAW无法正常工作该怎么办?

        ORG     0000H
COUNT   EQU     0X0FF   ; Use location 25H for counter
        CLRF    TRISB
R1      EQU     07
R2      EQU     08
R3      EQU     09
R4      EQU     10
        MOVLW   00H
        MOVWF   R1
REP1:
        MOVWF   PORTB
        CALL    DELAY
        INCF    PORTB,F
        MOVF    PORTB,W
        DAW
        GOTO    REP1
DELAY:
        MOVLW   D'20'
        MOVWF   R4
BACK:   
        MOVLW   D'100'
        MOVWF   R3
AGAIN:  
        MOVLW   D'250'
        MOVWF   R2
HERE:
        NOP
        NOP
        DECF    R2,F
        BNZ     HERE
        DECF    R3,F
        BNZ     AGAIN
        DECF    R4,F
        BNZ     BACK
        RETURN
        END

1 个答案:

答案 0 :(得分:0)

您发布的代码可以按照您想要的方式工作。

您似乎想念的是使PIC18F458以正常方式“工作”所需的所有额外东西。

这是在MPLAB仿真器中可以使用的代码:

;
;   Filename:       main.asm
;   Author:         dan1138
;   Target:         PIC18F458
;   Assembler:      MPASMWIN v5.22
;   Assembler mode: Absolute
;
;   Files required: p18f458.inc
;
;   Description:
;
;   Increment a BCD value in the PORTB output latch register.
;
    list P=18F458, r=dec, n=0, c=255
#include "p18f458.inc"
;
; Setup configuration words
    config OSC      = HS
    config BOR      = OFF
    config BORV     = 45
    config PWRT     = OFF
    config WDTPS    = 128
    config WDT      = OFF
    config STVR     = ON
    config LVP      = OFF
    config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
    config CPD = OFF, CPB = OFF
    config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
    config WRTD = OFF, WRTB = OFF, WRTC = OFF
    config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    config EBTRB = OFF
;
;   /* Specify the System clock frequency in Hz */
#define FSYS 10000000

;   /* Specify the Peripheral clock frequency in Hz */
#define FCYC (FSYS/4)
;
; Power On Reset entry point
    org     0
    goto    start
;
; Interrupt Service Routine entry point
    org 0x08
ISR_vevtor:
    retfie  1
;
; Declare application RAM in access bank
 cblock 0x07
    R1:1
    R2:1
    R3:1
    R4:1
 endc
;
; Main application start
start:
    clrf    INTCON          ; Disable all interrupts
    movlw   0x07
    movwf   ADCON1          ; Make ADC analog inputs digital I/O pins
    movlw   0x07
    movwf   CMCON           ; Make comparator analog inputs digital I/O pins
;
; Main application loop
        CLRF    TRISB       ; Make PORTB pins digital output
        MOVLW   00H
        MOVWF   R1          ; Set RAM location R1 to zero, don't know why.
        MOVLW   00H         ; Load WREG with initial BCD value
REP1:
        MOVWF   LATB        ; Write the WREG to PORTB outputs
        CALL    DELAY       ; Wait for about one second with a 10MHz system clock
        INCF    LATB,W      ; Increment output latch, put result in the WREG
        DAW                 ; Adjust the value in WREG to be BCD
        GOTO    REP1        ; Do it again.
DELAY:
        MOVLW   D'20'       ; Delay for about one second.
        MOVWF   R4          ; You figure out how it works.
BACK:   
        MOVLW   D'100'
        MOVWF   R3
AGAIN:  
        MOVLW   D'250'
        MOVWF   R2
HERE:
        NOP
        NOP
        DECF    R2,F
        BNZ     HERE
        DECF    R3,F
        BNZ     AGAIN
        DECF    R4,F
        BNZ     BACK
        RETURN
    end