装配PIC16F84A 0-99 porta = tens portb = 1

时间:2015-04-30 22:11:20

标签: assembly pic

我正在尝试计数从00到99的计数器,PORTB上的0-3引脚从1到9计数,当达到9时,PORTA应该增加1,然后返回到portb子程序等等,我最近开始学习装配,我的逻辑告诉我这应该有效,但事实并非如此,为什么呢?这是我的代码:

list p=16f84A
include <p16f84A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC 

org 0

;SETTING PORTS

BSF 03h,5 ;Changing STATUS to bank 1
MOVLW B'00000' ; Set all pins on
MOVWF 85h      ; PortA to output
MOVLW B'00000000' ;Set all pins on
MOVWF 86h         ; PortB to output
BCF 03h,5         ;Changing STATUS to bank 0
MOVLW 00h   ;Starting portA pins
MOVWF 05h   ; on cero
MOVLW 00h   ;Starting portB pins
MOVWF 06h   ; on cero
MOVLW 09h   ; Saving 9 on W
MOVWF 0Ch   ; Loading that 9 into the general purpose register 0Ch
MOVLW 09h   ; Saving 9 on W
MOVWF 0Dh   ; Loading that 9 into the general purpose register 0Dh

;START OF CODE

START
    MOVLW 09h ; Loading general purpose register 
    MOVWF 0Ch ; 0Ch with 9
    MOVLW 00h ; Setting PORTB
    MOVWF 06h ; pins all to 0
    GOTO START1 ; 

START1
    INCF 06h ;Incrementing PORTB by 1
    DECFSZ 0Ch ; Decrementing general purpose 0Ch previously set to 9, by 1, skip next instruction if 0Ch=0
    GOTO START1
    GOTO START2

START2
    INCF 05h ; Increment PORTA by 1
    DECFSZ 0Dh ; Decrementing general purpose 0Dh previously set to 9 by 1, skip next instruction if 0Dh=0
    GOTO START ; Goes back to START
    GOTO STARTOFSTARTS ; Goes to the label that sets everything back to their original values

STARTOFSTARTS 
    MOVLW 00h ; 
    MOVWF 05h ;Places all pins of PORTA on 0V
    MOVLW 00h ;
    MOVWF 06h ;Places all pins of PORTB on 0V
    MOVLW 09h ; 
    MOVWF 0Ch ;Loads general purpose 0Ch with 9
    MOVLW 09h ;
    MOVWF 0Dh ;Loads general purpose 0Dh with 9
    GOTO  START  goes back to start from 0 because 99 was already reached
    END

enter image description here

0 个答案:

没有答案
相关问题