微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PIC16F886-设置配置位

如何解决PIC16F886-设置配置位

尝试设置PIC16F886上的配置位时遇到语法错误
问题在于存在两个配置字,并且两个配置具有多个位。
因此,它无法与PIC10F206一起工作。
我正在使用pic-as v2.20工具链。

PROCESSOR 16F886
RADIX DEC
    
#include <xc.inc>
 
;this did not work:
;config DEBUG = ON,LVP = OFF,FcmeN = OFF,IESO = OFF,BOREN = OFF
;config CPD = OFF,CP = OFF,MCLRE = OFF,PWRTE = OFF,WDTE = OFF,FOSC = OFF
    
;this did not work:    
;config 0000000000000000000000000000
 
;this did not work:
;config 0x00

;this did not work:
;config config1 0x0000
;config config2 0x0000
    
    
    PSECT   StartCode,class=CODE,delta=2
    global  Start
Start:
    movlw 11000000B  ;set option register
    ;option is not in the p16f886 instruction summary
    movwf 81h  ;option_reg is at 81h (bank 1)
    
    movlw 11111110B  ;everything to input except for RA0
    tris 05h  ;05h is TRISA
    
    bcf 05h,0  ;clear bit zero in TRISA register
    ;the led on RA0 should light up Now
    
    sleep

END Start

解决方法

我怀疑您有一个问题使大多数不熟悉Microchip控制器的人感到困惑。具有模拟功能的GPIO引脚在配置为数字模式之前无法很好地工作。

此代码会将PORTA位RA0设置为数字输出,并每秒将其高低切换两次。

;
; File:     main.S
; Target:   PIC16F886
; Author:   dan1138
; Date:     2020-09-08
; Compiler: pic-as(v2.20)
; IDE:      MPLABX v5.40
;
; Description:
;
;   Example project for the PIC16F886 controller using the pic-as(v2.20) tool chain.
;
; Add this line in the project properties box,pic-as Global Options -> Additional options:
;   -Wa,-a -Wl,-pPor_Vec=0h,-pIsr_Vec=4h
;
    PROCESSOR   16F886
    PAGEWIDTH   132
    RADIX       DEC

#include <xc.inc>

; CONFIG1
 config FOSC = INTRC_NOCLKOUT; Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin,I/O function on RA7/OSC1/CLKIN)
 config WDTE = OFF       ; Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
 config PWRTE = OFF      ; Power-up Timer Enable bit (PWRT disabled)
 config MCLRE = ON       ; RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
 config CP = OFF         ; Code Protection bit (Program memory code protection is disabled)
 config CPD = OFF        ; Data Code Protection bit (Data memory code protection is disabled)
 config BOREN = OFF      ; Brown Out Reset Selection bits (BOR disabled)
 config IESO = OFF       ; Internal External Switchover bit (Internal/External Switchover mode is disabled)
 config FCMEN = OFF      ; Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
 config LVP = OFF        ; Low Voltage Programming Enable bit (RB3 pin has digital I/O,HV on MCLR must be used for programming)

; CONFIG2
 config BOR4V = BOR21V   ; Brown-out Reset Selection bit (Brown-out Reset set to 2.1V)
 config WRT = OFF        ; Flash Program Memory Self Write Enable bits (Write protection off)

;
; Define macros to help with
; bank selection
;
#define BANK0  (0x000)
#define BANK1  (0x080)
#define BANK2  (0x100)
#define BANK3  (0x180)
;
; 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
;
; Power-On-Reset entry point
;
    PSECT   Por_Vec,global,class=CODE,delta=2
    global  resetVec
resetVec:
    PAGESEL Start
    goto    Start

;
;   Data space use by interrupt handler to save context
    PSECT   Isr_Data,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,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
;
; Initialize the PIC hardware
;
Start:
    clrf    INTCON              ; Disable all interrupt sources
    banksel BANK1
    clrf    PIE1
    clrf    PIE2

    movlw   0b01100000
    movwf   OSCCON              ; Set internal oscillator at 4MHz

    movlw   0b10000001          ; Pull-ups off,INT edge high to low,WDT prescale 1:1
    movwf   OPTION_REG          ; TMR0 clock edge low to high,TMR0 clock = FCY,TMR0 prescale 1:4
                                ; TIMER0 will assert the overflow flag every 256*4 (1024)
                                ; instruction cycles,with a 4MHz oscilator this ia 1.024 milliseconds.

    movlw   0b11111111         ;
    movwf   TRISA

    movlw   0b11111111         ;
    movwf   TRISB

    movlw   0b11111111         ;
    movwf   TRISC

    ; Set all ADC inputs for digital I/O
    banksel BANK3
    movlw   0b00000000
    movwf   ANSEL
    movlw   0b00000000
    movwf   ANSELH
    banksel BANK2
    clrf    CM1CON0             ; turn off comparator
    clrf    CM2CON0             ; turn off comparator
    banksel BANK1
    movlw   0b00000000
    movwf   ADCON1
    clrf    VRCON               ; turn off voltage reference
    banksel BANK0
    movlw   0b10000000
    movwf   ADCON0

    pagesel main
    goto    main
;
; Main application data
;
    PSECT   MainData,class=RAM,noexec
    global  count
count:  DS      1               ;reserve 1 byte for TOMER0 rollover count
;
; Main application code
;
    PSECT   MainCode,delta=2
;
; Function to Wait for TIMER0 to rollover 250 times
;
WaitOnTimer0:
    movlw   250
    BANKSEL count
    movwf   BANKMASK(count)
WaitT0a:
    bcf     INTCON,INTCON_TMR0IF_POSITION
WaitT0b:
    btfss   INTCON,INTCON_TMR0IF_POSITION
    goto    WaitT0b
    decfsz  BANKMASK(count),F
    goto    WaitT0a
    return
;
; Set PORTA bit 0 as an output then set low wait
; for 250 rollovers of TIMER0 and set hihg and
; wait another 250 rollovers of TIMER0 then loop
;
main:
    BANKSEL TRISA
    bcf     BANKMASK(TRISA),TRISA_TRISA0_POSITION   ; Make PORTA bit RA0 an output
loop:
    BANKSEL PORTA
    bcf     BANKMASK(PORTA),PORTA_RA0_POSITION      ; Make PORTA bit RA0 LOW
    call    WaitOnTimer0
    bsf     BANKMASK(PORTA),PORTA_RA0_POSITION      ; Make PORTA bit RA0 HIGH
    call    WaitOnTimer0
    goto    loop
;
; Declare Power-On-Reset entry point
;
    END     resetVec

尝试一下,让我知道如何进行。

,

感谢您的回答。
到目前为止,此代码有效。
它仍然不是完美的,就像我可能应该使用BANKSEL伪指令并使用变量而不是十六进制代码一样。
另外,在设置选项之前,我没有设置bank 1,所以可能不会起作用。

PROCESSOR 16F886
PAGEWIDTH   132
RADIX DEC
    
#include <xc.inc>
 
config DEBUG = OFF,LVP = OFF,FCMEN = OFF,IESO = OFF,BOREN = OFF
config CPD = OFF,CP = OFF,MCLRE = OFF,PWRTE = OFF,WDTE = OFF
config FOSC = INTRC_NOCLKOUT,BOR4V = BOR40V,WRT = OFF
    
    
    PSECT   StartCode,delta=2
    global  Start
Start:
    movlw 11000000B  ;set option register
    ;option is not in the p16f886 instruction summary
    movwf 81h  ;option_reg is at 81h (bank 1)
    
    movlw 00100000B  ;set the status register (select bank 1)
    movwf 03h  ;status register is at 03h
    
    movlw 11111110B  ;everything to input except for RA0
    ;there is no tris instruction on this processor
    movwf 85h  ;85h is TRISA register
    
    movlw 00000000B  ;set the status register (select bank 0)
    movwf 03h  ;status register is at 03h
    
    ;05h is PORTA
    bcf 05h,0  ;clear bit zero in PORTA register
    ;the led on RA0 should light up now
    
    sleep

END Start

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。