官方的 source code bug 一堆,我試了幾天,將發現的問題改過
並加入config ,及switch vr 的測試,LED 顯示改得較為美觀。
有 DM300027 DEMOBOARD 想測試的,可以試試看
目前未解決的問題:VR 在 DEBUG MODE 可以操作,但是PROGRMA 到單機之後就會恆為 0,原因不明。
#include "p24fj64ga002.h"
#define XTFREQ 7372800 //On-board Crystal frequency
#define PLLMODE 2 //On-chip PLL setting
#define FCY XTFREQ*PLLMODE //Instruction Cycle Frequency
#define BAUDRATE 9600
#define BRGVAL ((FCY/BAUDRATE)/16)-1
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx1 & FWDTEN_OFF & WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768 )
_CONFIG2( IESO_OFF & FNOSC_PRIPLL & FCKSM_CSDCMD & OSCIOFNC_OFF & IOL1WAY_OFF & I2C1SEL_PRI & POSCMOD_XT )
int vr=0;
int main(void)
{
CLKDIVbits.RCDIV = 0;
RPINR18bits.U1RXR = 9; // Make Pin RP9 U1RX
RPOR4bits.RP8R = 3; // Make Pin RP8 U1TX
LATB = 0x00;
TRISB = 0x0FFF; // Configure LED pins as output
TMR1 = 0; // Clear timer 1
PR1 = 0x3D09; // Interrupt every 250ms
IFS0bits.T1IF = 0; // Clear interrupt flag
IEC0bits.T1IE = 1; // Set interrupt enable bit
T1CON = 0x8020; // Fosc/4, 1:256 prescale, start TMR1
U1BRG = BRGVAL;
U1MODE = 0x8000; // Reset UART to 8-n-1, alt pins, and enable
U1STA = 0x0440; // Reset status register and enable TX & RX
_U1RXIF=0; // Clear UART RX Interrupt Flag
while(1)
{
int a,b,c;
while (_U1RXIF==0); // Wait and Receive One Character
a = U1RXREG;
while(!U1STAbits.TRMT); // Echo Back Received Character with quotes
U1TXREG = a;
if(a == 0x0d){
while(!U1STAbits.TRMT); // Echo Back Received Character with quotes
U1TXREG = 0x0a;
}
_LATB12=0;
_U1RXIF=0; // Clear UART RX Interrupt Flag
}
return 0;
}
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void)
{
IFS0bits.T1IF = 0; // clear interrupt flag
// LATB ^= 0xE000; //Toggle LED's
LATB =((LATB&0XF000)<<1);
_LATB12=1;
if(_RB5 ==0)_LATB12=0;
if(_RB3 ==1){
_TRISB3=1;
if(vr ==0){_LATB12=0;vr =1;}
else {_LATB12=1;vr =0;}
}
}