PICkit4로 PIC16F886 디버깅
MCU : Pic16F886
프로그래머 : PICkit4
IDE : MPLAB X IDE v5.40
어셈블러 : pic-as v2.30 (xc8)
회로 :
RA0에 270ohm 저항이있는 LED.
MCLRE의 3,3k 옴 저항 풀업 저항.
핀 20의 Vdd.
핀 19의 Vss .
이것은 디버그하고 싶은 테스트 코드입니다.
PROCESSOR 16F886
PAGEWIDTH 132
RADIX DEC
#include <xc.inc>
config DEBUG = ON, LVP = OFF, FCMEN = OFF, IESO = OFF, BOREN = OFF
config CPD = OFF, CP = OFF, MCLRE = OFF, PWRTE = OFF, WDTE = OFF
config FOSC = INTRC_NOCLKOUT, LVP = OFF, BOR4V = BOR40V, WRT = OFF
PSECT StartCode,class=CODE,delta=2
global Start
Start:
movlw 11000000B ;set option register
movwf OPTION_REG
movlw 00100000B ;set the status register (select bank 1)
movwf STATUS
movlw 11111110B ;everything to input except for RA0
movwf TRISA
movlw 00000000B ;set the status register (select bank 0)
movwf STATUS
bcf PORTA, 0 ;clear bit zero in PORTA register
sleep
END Start
프로젝트를 실행하면 코드가 예상대로 작동합니다.
그러나 중단 점을 설정하고 "Debug Main Project"를 누르면 오류가 발생합니다. Reception on endpoint 129 failed (err = -10121)
또는 구성 설정을 사용하여 작업하면 프로세스를 종료 할 때까지 몇 분 동안 "빌드,로드"상태로 유지됩니다.
PIC16886에는 데이터 시트 1 페이지와 블록 다이어그램에 따라 "인-서킷 디버거 (온보드)"가 있습니다.
답변
PICkit4에서 불안정성의 원인이 될 수있는 몇 가지가 있습니다.
게시 한 코드가 훨씬 더 좋을 수 있으므로 여기에 사용자 정의 제작 된 PIC16F886 어셈블리 언어 예제가 있습니다.
;
; File: main.S
; Target: PIC16f886
; Author: dan1138
; Date: 2020-09-29
; Compiler: pic-as(v2.20)
; IDE: MPLABX v5.40
;
; PIC16F886
; +---------:_:---------+
; VPP RE3 -> : 1 MCLRn PGD 28 : <> RB7 PGD
; RA0 <> : 2 AN0 PGC 27 : <> RB6 PGC
; RA1 <> : 3 AN1 AN13 26 : <> RB5
; RA2 <> : 4 AN2 AN11 25 : <> RB4
; RA3 <> : 5 AN3 AN9/PGM 24 : <> RB3
; RA4 <> : 6 T0CKI AN8 23 : <> RB2
; RA5 <> : 7 AN4 AN10 22 : <> RB1
; GND -> : 8 VSS AN12 21 : <> RB0
; RA7 <> : 9 OSC1 VDD 20 : <- 5v0
; RA6 <> : 10 OSC2 VSS 19 : <- GND
; RC0 <> : 11 SOSCO RX 18 : <> RC7
; RC1 <> : 12 SOSCI TX 17 : <> RC6
; RC2 <> : 13 CCP1 SDO 16 : <> RC5
; RC3 <> : 14 SCL SDI 15 : <> RC4
; +---------------------+
; DIP-28
; 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>
; PIC16F887 Configuration Bit Settings
; 'C' source line config statements
; 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 = ON ; Internal External Switchover bit (Internal/External Switchover mode is enabled)
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 = BOR40V ; Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
config WRT = OFF ; Flash Program Memory Self Write Enable bits (Write protection off)
;
; Power-On-Reset entry point
;
PSECT Por_Vec,global,class=CODE,delta=2
global resetVec
resetVec:
PAGESEL main ;jump to the main routine
goto main
;
; Data space use by interrupt handler to save context
PSECT Isr_Data,global,class=RAM,space=1,delta=1,noexec
;
GLOBAL WREG_save,STATUS_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,F
retfie ; Return from interrupt
;
; Main application
;
PSECT MainCode,global,class=CODE,delta=2
main:
clrf INTCON ; disable all interrupts
banksel PIE1
clrf BANKMASK(PIE1)
clrf BANKMASK(PIE2)
banksel OSCCON ; Select INTOSC at 8MHz
movlw 0x70
movwf BANKMASK(OSCCON)
banksel ANSEL ; Make all GPIO us digital mode
clrf BANKMASK(ANSEL)
clrf BANKMASK(ANSELH)
banksel PORTA ; Make all output zero
clrf BANKMASK(PORTA)
clrf BANKMASK(PORTB)
clrf BANKMASK(PORTC)
banksel TRISA ; Select input and output GPIOs
clrf BANKMASK(TRISA) ; Make RA0-RA7 outputs
movlw 0x01
movwf BANKMASK(TRISB) ; Make RB0 an input, RB1-RB7 outputs
clrf BANKMASK(TRISC) ; Make all PORTC outputs
banksel OPTION_REG
movlw 0xDF
movwf BANKMASK(OPTION_REG) ; Set TIMER0 clock source to FOSC/4, prescale 1:1, WDT prescale 1:128
;
;
;
banksel WDTCON ; Enable WDT timeout
bsf BANKMASK(WDTCON),WDTCON_SWDTEN_POSITION
loop:
banksel PORTA
movlw 0x01
xorwf PORTA,F
sleep ; typical sleep time 2.048 seconds
nop
pagesel loop
goto loop
;
; Tell linker the power on reset entry point
;
END resetVec
PICkit4에 도움이 될 수있는 또 다른 방법은 MPLABX 통합 프로그래밍 환경 (IPE) 도구를 사용하여 "하드웨어 도구 비상 부팅 펌웨어 복구"를 수행하는 것입니다.
이것은 올바르게 수행하기 전에 몇 번의 시도가 필요할 수있는 까다로운 프로세스입니다. 프로세스의 적절한 단계에서 PICkit4의 플러그를 뽑고 꽂아야합니다.
최악의 경우는 MPLABX v5.40 설치가 어떻게 든 손상되었다는 것입니다. 이를 제거하려면 이전 MPLABX 설치의 나머지 부분이 삭제되었는지 확인한 다음 모두 다시 설치해야합니다. 10 ~ 15 번만하면 엄청나게 성가시다.