PIC16F1455目前使用遇到的問題?

作者 guncen 於 2017年04月11日 23:52:41
各位先進好:
目前我使用的MPLAB X IDE v3.45+XC8 V1.41+PICkit3
完整程式碼如下:
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config CPUDIV = NOCLKDIV// CPU System Clock Selection Bit (NO CPU system divide)
#pragma config USBLSCLK = 24MHz // USB Low SPeed Clock Selection bit (System clock expects 24 MHz, FS/LS USB CLKENs divide-by is set to 4.)
#pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected)
#pragma config PLLEN = DISABLED // PLL Enable Bit (3x or 4x PLL Disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

//#define baud 0x17//0x17 for 48MHz -> 31250 baud
#define baud 0x13//0x13 for 48MHz -> 38400 baud

void InitializeSystem(void);
void UserInit(void);
void InitializeUSART(void);

#define InitGpio() TRISA = 0b00001000;\
TRISC = 0b00000000;\

#define GLed LATCbits.LATC3


union{
struct{
unsigned T0 :1; //
unsigned T1 :1; //
unsigned T2 :1; //
unsigned T3 :1; //
unsigned T4 :1; //
unsigned T5 :1; //
unsigned T6 :1; //
unsigned T7 :1; //
}oneBit;
unsigned char allBits;
}Time_FLAG;
#define interrupt_1ms Time_FLAG.oneBit.T0

unsigned char rc_temp;

#define UART_TRISTx TRISCbits.TRISC4
#define UART_TRISRx TRISCbits.TRISC5


void interrupt ISRCode()
{
if(TMR0IF && TMR0IE)
{
TMR0 = 0x00;
TMR0IF = 0 ;
interrupt_1ms = 1;
}

if(RCIF && RCIE)
{
RCIF = 0;
rc_temp = RCREG; //硬體接收器的值存到接收暫存器
TXREG = rc_temp;

}
}

void main(void) {
InitializeSystem();
while(1)
{
if(rc_temp==0)
{
GLed = 1;
}
else
{
GLed = 0;
}

}
}

void InitializeSystem(void)
{
ANSELA = 0;
ANSELC = 0;

//OSCCONbits.IRCF = 0x0f; //16MHz HFINTOSC with 3x PLL enabled (48MHz operation)
//OSCCONbits.SCS = 0x00;
//OSCCONbits.SPLLEN = 1;
//OSCCONbits.SPLLMULT = 1;
OSCCON = 0b11111100;
ACTCONbits.ACTSRC = 1; //Enable active clock tuning with USB
ACTCONbits.ACTEN = 1;

UserInit();
OPTION_REG = 0;
TMR0 = 0x05;
INTCON = 0b11100000;
}

void UserInit(void)
{
InitGpio();
InitializeUSART();
}//end UserInit

void InitializeUSART(void)
{
unsigned char c;
//unsigned char cnt=0;

UART_TRISTx = 0;
UART_TRISRx = 1;
TXSTA = 0x20; // TX enable BRGH=0
RCSTA = 0x90; // Single Character RX
SPBRG = baud;

BAUDCON = 0x00; // BRG16 = 0

PIE1bits.RCIE = 1;

c = RCREG; // read
}

遇到的問題是,DEBUG模式下進行實際量測IO輸出腳與UART傳輸都正確,但是燒錄後拔開PICkit3實際量測IO輸出一直維持HI(沒有如程式中切換),UART傳輸一樣正確.
請問這樣應該要怎麼查詢問題點可能在哪邊?

來自: http://www.microchip.com.tw/newbb/viewtopic.php?forum=1&topic_id=20580&post_id=74822