在使用MPLAB X IDE v6.00在PIC16F877A上使用TMR0创建延迟例程时,我需要纠正什么



我正在用mpsam迁移在mplab中开发的一个旧程序,但我找不到方法来解决在新的mplab X IDE v4.0中用pic生成错误的两行代码。附件是迁移后的代码,指出它在哪里生成错误。


#include <xc.inc>
CONFIG  FOSC = HS             
CONFIG  WDTE = OFF            
CONFIG  PWRTE = ON           
CONFIG  BOREN = OFF         
CONFIG  LVP = OFF             
CONFIG  CPD = OFF             
CONFIG  WRT = OFF            
CONFIG  CP = OFF             
ORG     0x00
GOTO    INICIO
ms_20:
clrf    TMR0
;The following line gives me an error          
movlw   .80          
xorwf   TMR0,w
;The following line gives me an error
bnz     $-3
return
INICIO:
bsf STATUS, 5
bcf STATUS, 6
movlw   00000000B
movwf   TRISB
movlw   00000111B
movwf   OPTION_REG
bcf STATUS, 5
bcf STATUS, 6
clrf    PORTB
bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0
m0:
bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0
END

旧版本中的原始代码如下:

LIST P=16F877A
INCLUDE<P16F877A.INC>
_CONFIG 0x3F31
ORG 0x00
goto INICIO
ms_20   clrf   TMR0
movlw  .80
xorwf  TMR0,w
bnz    $-3
return
INICIO  bsf STATUS, 5
bcf STATUS, 6
movlw   B'00000000'
movwf   TRISB
movlw   B'00000111'
movwf   OPTION_REG
bcf STATUS, RP0
bcf STATUS, RP1
clrf    PORTB
bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0

m0      bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0
END

将汇编代码从MPASM移植到pic作为汇编程序有很多问题。

以下是作为汇编程序移植到pic的代码示例:

;
; File:     main.S
; Target:   PIC16F877A
; Author:   dan1138
; Date:     2020-10-09
; Compiler: pic-as(v2.40)
; IDE:      MPLABX v6.00
;
; Description:
;
;   Example for https://stackoverflow.com/questions/73941514/what-do-i-need-to-correct-in-the-creation-of-delay-routine-using-tmr0-on-the-pic
;
; Add this line in the project properties box, pic-as Global Options -> Additional options:
;   -Wa,-a -Wl,-pPor_Vec=0h,-pIsr_Vec=4h
;
PROCESSOR   16F877A
PAGEWIDTH   132
RADIX       DEC
;
#include <xc.inc>
; PIC16F877A Configuration Bit Settings
; 'C' source line config statements
; CONFIG
config FOSC = HS        ; Oscillator Selection bits (HS oscillator)
config WDTE = OFF       ; Watchdog Timer Enable bit (WDT disabled)
config PWRTE = OFF      ; Power-up Timer Enable bit (PWRT disabled)
config BOREN = OFF      ; Brown-out Reset Enable bit (BOR disabled)
config LVP = OFF        ; Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
config CPD = OFF        ; Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
config WRT = OFF        ; Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
config CP = OFF         ; Flash Program Memory Code Protection bit (Code protection off)
;
; Skip macros
;
skipnc  MACRO
btfsc   STATUS,STATUS_C_POSITION
ENDM
skipc   MACRO
btfss   STATUS,STATUS_C_POSITION
ENDM
skipnz  MACRO
btfsc   STATUS,STATUS_Z_POSITION
ENDM
skipz   MACRO
btfss   STATUS,STATUS_Z_POSITION
ENDM
;
; Branch macros
;
bnz     MACRO arg
btfss   STATUS,STATUS_Z_POSITION
goto    arg
ENDM
bz      MACRO arg
btfsc   STATUS,STATUS_Z_POSITION
goto    arg
ENDM
bnc     MACRO arg
btfss   STATUS,STATUS_C_POSITION
goto    arg
ENDM
bc      MACRO arg
btfsc   STATUS,STATUS_C_POSITION
goto    arg
ENDM
;
; Power-On-Reset entry point
;
PSECT   Por_Vec,global,class=CODE,delta=2
global  resetVec
resetVec:
PAGESEL INICIO
goto    INICIO
;
;   Data space use by interrupt handler to save context
PSECT   Isr_Data,global,class=COMMON,space=1,delta=1,noexec
;
GLOBAL  WREG_save,STATUS_save,PCLATH_save
;
WREG_save:      DS  1
STATUS_save:    DS  1
PCLATH_save:    DS  1
;
;   Interrupt vector and handler
PSECT   Isr_Vec,global,class=CODE,delta=2
GLOBAL  IsrVec
;
IsrVec:
movwf   WREG_save
swapf   STATUS,W
movwf   STATUS_save
movf    PCLATH,W
movwf   PCLATH_save
;
IsrHandler:
;
IsrExit:
movf    PCLATH_save,W
movwf   PCLATH
swapf   STATUS_save,W
movwf   STATUS
swapf   WREG_save,F
swapf   WREG_save,W
retfie                      ; Return from interrupt
;
;   Section used for main code
PSECT   MainCode,global,class=CODE,delta=2
ms_20:
clrf   TMR0
movlw  80
xorwf  TMR0,w
bnz    $-3
return
INICIO: bsf     STATUS,STATUS_RP0_POSITION
bcf     STATUS,STATUS_RP1_POSITION
movlw   0b00000000
movwf   TRISB
movlw   0b00000111
movwf   OPTION_REG
bcf     STATUS,STATUS_RP0_POSITION
bcf     STATUS,STATUS_RP1_POSITION
clrf    PORTB
bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0
m0:     bsf     PORTB,0
call    ms_20
bcf     PORTB,0
call    ms_20
goto    m0
;
; Declare Power-On-Reset entry point
;
END     resetVec

这取决于你去做研究,去理解发生了什么变化以及为什么。

相关内容

  • 没有找到相关文章

最新更新