//****************************************************************************************** // dsPIC33FJ256GP506 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H22.11.15 // History : // Laungage : MPLAB C30 //****************************************************************************************** // (1)Description // OSC: Internal OSC 7.37MHz * PLL ==> 79.23MHz //****************************************************************************************** #include "string.h" #include "stdio.h" #include "ctype.h" #include "math.h" #include "stdlib.h" #include "time.h" #include "p33FJ256GP506.h" //_FBS(RBS_NO_BOOT_RAM & BSS_NO_BOOT_CODE & BWRP_WRPROTECT_OFF); //_FSS(RSS_NO_RAM & SSS_NO_SEC_CODE & SWRP_WRPROTECT_OFF); //_FGS(GSS_OFF & GCP_OFF & GWRP_OFF ); //_FOSCSEL(FNOSC_FRC & IESO_OFF); _FOSCSEL(FNOSC_FRCPLL & IESO_OFF); _FOSC(FCKSM_CSECMD & OSCIOFNC_ON & POSCMD_NONE ); //_FWDT(FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR32 & WDTPOST_PS1); //_FPOR(FPWRT_PWR1); //_FICD(BKBUG_ON & COE_ON & JTAGEN_ON & ICS_PGD1); _FWDT(FWDTEN_OFF); #define PI 3.141592 #define MAX_DATA 1000 #define Range 0xFFFF/3 void Timer(void); int main(void) { unsigned int table_i[MAX_DATA +1]; unsigned int lp; float tmp_f; // ******************* // 1.Initialize // ******************* // (1)Define OSC 79.23MHz(7.37MHz/2*43(M43)/2) CLKDIV = 0b0000000000000000; // PLLFBD = 0x001E; //M32 PLLFBD = 0x0029; //M43(M43-2=>0d41=>0x29) // (2)Set All Digital Port AD1PCFGL = 0xFFFF; AD1PCFGH = 0xFFFF; // (3)Define PortB TRISB = 0x0000; PORTB = 0x0000; // ******************* // 2.Program Main // ******************* // (1)Set Initial Value for(lp=0;lp: Timerx Input Clock Prescale Select bits // 11 = 1:256 // 10 = 1:64 // 01 = 1:8 // 00 = 1:1 // TxCON[3] T32: 32-bit Timer Mode Select bit(1) // 1 = Timerx and Timery form a single 32-bit timer // 0 = Timerx and Timery act as two 16-bit timers // TxCON[2] Unimplemented: Read as e0f // TxCON[1] TCS: Timerx Clock Source Select bit // 1 = External clock from pin TxCK (on the rising edge) // 0 = Internal clock (FCY) // TxCON[0] Unimplemented: Read as e0f // *********************************************** // T2CON = 0b1000000000100000; // Prescaler 1/64, 16Bit // T2CON = 0b1000000000110000; // Prescaler 1/256,16Bit T2CON = 0b1000000000000000; // Prescaler 1/1, 16Bit // *********************************************** // 2.Set PR2-Register // *********************************************** // PR2 = 0x186A; // 10Hz (0x186a;0d6250) //FRC 8MHz 8MHz/2/64/10 // PR2 = 0x167D; // 10Hz (0x167D;0d5758) //FRC 7.37MHz 7.37MHz/2/64/10 // PR2 = 0x3C72; // 10Hz (0x3C72;0d15474) //FRC 79.23MHz 79.23MHz/2/256/10 PR2 = 0x0318; // 50KHz (0x0318;0d792) //FRC 79.23MHz 79.23MHz/2/1/50000 // PR2 = 0x9ABF; // 1KHz (0x9ABF;0d39615) //FRC 79.23MHz 79.23MHz/2/1/1000 // *********************************************** // 3.Timer // *********************************************** // TMR2 = 0; IFS0bits.T2IF = 0; while(1){ if(IFS0bits.T2IF != 0 )break; } }