//****************************************************************************************** // PIC32MX120F032B Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H24.06.09 // History : // Laungage : MPLAB C32 //****************************************************************************************** // (1)Description // Internal OSC PLL 40MHz (8MHz/2*20/2) //****************************************************************************************** //#include #include // //Define configration // #pragma config PMDL1WAY = OFF //Peripheral Module Disable Configuration:Allow multiple reconfigurations #pragma config IOL1WAY = OFF //Peripheral Pin Select Configuration:Allow multiple reconfigurations #pragma config FUSBIDIO = OFF //USB USID Selection:Controlled by Port Function #pragma config FVBUSONIO = OFF //USB VBUS ON Selection:Controlled by Port Function //#pragma config FPLLIDIV= DIV_1 //PLL Input Divider:1x Divider (DIV_1,DIV_2,DIV_3,DIV_4,DIV_5,DIV_6,DIV_10,DIV_12) #pragma config FPLLIDIV = DIV_2 //#pragma config FPLLMUL = MUL_15 //PLL Multiplier:15x Multiplier(MUL_15,MUL_16,MUL_17,MUL_18,MUL_19,MUL_20,MUL_21,MUL_24) #pragma config FPLLMUL = MUL_20 //#pragma config FPLLODIV= DIV_1 //System PLL Output Clock Divider:PLL Divide by 1(DIV_1,DIV_2,DIV_4,DIV_8,DIV_16,DIV_32,DIV_64,DIV_256) #pragma config FPLLODIV = DIV_2 //#pragma config FNOSC = FRC //Oscillator Selection Bits:Fast RC Osc (FRC) (FRC,FRCPLL,PRI,PRIPLL,SOSC,LPRC,FRCDIV16,FRCDIV) #pragma config FNOSC = FRCPLL #pragma config FSOSCEN = OFF //Secondary Oscillator Enable:Disabled #pragma config IESO = OFF //Internal/External Switch Over:Disabled #pragma config POSCMOD = OFF //Primary Oscillator Configuration:Primary osc disabled (EC,XT,HS,OFF) #pragma config OSCIOFNC = OFF //CLKO Output Signal Active on the OSCO Pin::Disabled #pragma config FPBDIV = DIV_1 //Peripheral Clock Divisor:Pb_Clk is Sys_Clk/1 (DIV_1,DIV_2,DIV_4,DIV_8) #pragma config FCKSM = CSDCMD //Clock Switching and Monitor Selection:Clock Switch Disable, FSCM Disabled (CSECME,CSECMD,CSDCMD) #pragma config WDTPS = PS1 //Watchdog Timer Postscaler:1:1 (PS1,,,,PS1048576) #pragma config WINDIS = OFF //Watchdog Timer Window Enable:Watchdog Timer is in Non-Window Mode #pragma config FWDTEN = OFF //Watchdog Timer Enable:WDT Disabled (SWDTEN Bit Controls) #pragma config FWDTWINSZ = WINSZ_50//Watchdog Timer Window Size:Window Size is 50% (WINSZ_75,WINSZ_50,WINSZ_37,WISZ_25) #pragma config DEBUG = OFF //Background Debugger Enable:Debugger is Disabled #pragma config JTAGEN = OFF //JTAG Enable:JTAG Disabled #pragma config ICESEL = RESERVED//ICE/ICD Comm Channel Select:Reserved (RESERVED,ICS_PGx3,ICS_PGx2,ICS_PGx1) #pragma config PWP = OFF //Program Flash Write Protect: #pragma config BWP = OFF //Boot Flash Write Protect bit: #pragma config CP = OFF //Code Protect: // //Define function // #define TIM 1000 void wat(unsigned int); void Timer(void); void mvLED(unsigned int *); int main(void) { unsigned int LEDlst; // 32bit // ******************* // 1.Define PORT // ******************* // (1)Define PortB TRISB = 0x00000000; // 32bit LATB = 0x00000000; // 32bit PORTB = 0x00000000; // 32bit // (2)Set Initial Vale LEDlst = 0x00000001; PORTB = LEDlst; // ******************* // 2.Program Main // ******************* while(1){ wat(10) ; mvLED(&LEDlst); } } //****************************************************************************************** // Function Name : mvLED // Title : Move LED function // Input : // Output : //****************************************************************************************** void mvLED(unsigned int *LEDlst) { if(*LEDlst == 1){ *LEDlst = 2; }else if(*LEDlst > 127){ *LEDlst = 1; }else{ *LEDlst = *LEDlst * 2; } PORTB = *LEDlst; } //****************************************************************************************** // Function Name : wat // Title : // Input : 0.1[S] * n // Output : //****************************************************************************************** void wat(unsigned int no) { unsigned int lp; for(lp=0;lp