Debug di PIC16F886 con PICkit4
MCU: Pic16F886
Programmatore: PICkit4
IDE: MPLAB X IDE v5.40
Assemblatore: pic-as v2.30 (xc8)
Circuito:
un LED con resistenza da 270 ohm su RA0.
Resistenza pull-up da 3,3k ohm su MCLRE.
Vdd sul pin 20.
Vss sul pin 19.
Questo è il codice di prova che voglio eseguire il debug e passare da un'istruzione all'altra:
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
Quando eseguo il progetto il codice funziona come previsto.
Ma quando imposto un punto di interruzione e premo "Debug Main Project" ottengo l'errore: Reception on endpoint 129 failed (err = -10121)
Oppure rimane nello stato "build, load" per minuti finché non esco dal processo se gioco con le impostazioni di configurazione.
Il PIC16886 ha un "debugger in-circuit (a bordo)" secondo la pagina 1 del datasheet e lo schema a blocchi.
Risposte
Ci sono alcune cose che potrebbero essere la causa dell'instabilità nel tuo PICkit4.
Il codice che hai pubblicato potrebbe essere molto migliore, quindi ecco un esempio di linguaggio assembly PIC16F886 personalizzato per te:
;
; 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
Un'altra cosa che può aiutare o brickare il tuo PICkit4 è usare lo strumento MPLABX Integrated-Programming-Environment (IPE) per eseguire un "Ripristino del firmware di avvio di emergenza dello strumento hardware".
Questo è un processo complicato che potrebbe richiedere alcuni tentativi prima di eseguirlo correttamente. Sarà necessario scollegare e collegare PICkit4 nei passaggi appropriati del processo.
Il caso peggiore per te è che la tua installazione di MPLABX v5.40 è in qualche modo danneggiata. Ciò richiederà di disinstallarlo, assicurarsi che eventuali resti delle precedenti installazioni di MPLABX siano stati eliminati, quindi installare di nuovo tutto. Dopo aver fatto le sole 10 o 15 volte diventa solo mostruosamente fastidioso.