⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blinkled.c

📁 Sample program on how to blink LEDs attached on PIC32 microcontroller I/O pins.
💻 C
字号:
#include <plib.h> /* include PIC32 peripheral library */

/**********************
 * Configuration Bits *
 **********************/
//SETUP THE DEBUGG PORT FOR PIC32. THE HARDWARE IS MAPPED TO DEBUG PORT 1 (PGC1, PGD1)
//configuration bits can alternately set by going to "Configure->Configuration Bits" 
//and unchecking the "Configuration Bits Set In Code" checkbox

#ifndef OVERRIDE_CONFIG_BITS
        
    #ifdef USB_A0_SILICON_WORK_AROUND
        #pragma config UPLLEN   = OFF       // USB PLL Enabled (A0 bit inverted)
    #else
        #pragma config UPLLEN   = ON        // USB PLL Enabled
    #endif
    
    #pragma config FPLLMUL  = MUL_15        // PLL Multiplier
    #pragma config UPLLIDIV = DIV_2         // USB PLL Input Divider
    #pragma config FPLLIDIV = DIV_2         // PLL Input Divider
    #pragma config FPLLODIV = DIV_1         // PLL Output Divider
    #pragma config FPBDIV   = DIV_1         // Peripheral Clock divisor
    #pragma config FWDTEN   = OFF           // Watchdog Timer
    #pragma config WDTPS    = PS1           // Watchdog Timer Postscale
    #pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor
    #pragma config OSCIOFNC = OFF           // CLKO Enable
    #pragma config POSCMOD  = HS            // Primary Oscillator
    #pragma config IESO     = OFF           // Internal/External Switch-over
    #pragma config FSOSCEN  = ON            // Secondary Oscillator Enable (KLO was off)
    #pragma config FNOSC    = PRIPLL        // Oscillator Selection
    #pragma config CP       = OFF           // Code Protect
    #pragma config BWP      = OFF           // Boot Flash Write Protect
    #pragma config PWP      = OFF           // Program Flash Write Protect
    #pragma config ICESEL   = ICS_PGx1      // ICE/ICD Comm Channel Select
    
    #ifdef __DEBUG
        #pragma config DEBUG    = ON        // Background Debugger Enable
    #else
        #pragma config DEBUG    = OFF       // Background Debugger Disable
    #endif
            
#endif // OVERRIDE_CONFIG_BITS



int main(void)
{
	int i; //delay loop variable

	/* Setup LEDs */
	mPORTCSetPinsDigitalOut(BIT_1);
	mPORTCSetPinsDigitalOut(BIT_2);
	mPORTCSetPinsDigitalOut(BIT_3);
	mPORTCSetPinsDigitalOut(BIT_4);

	mPORTGSetPinsDigitalOut(BIT_12);
	mPORTGSetPinsDigitalOut(BIT_13);
	mPORTGSetPinsDigitalOut(BIT_14);
	mPORTGSetPinsDigitalOut(BIT_15);

	/* LEDs are off initially */
	mPORTCClearBits(BIT_1);
	mPORTCClearBits(BIT_2);
	mPORTCClearBits(BIT_3);
	mPORTCClearBits(BIT_4);

	mPORTGClearBits(BIT_12);
	mPORTGClearBits(BIT_13);
	mPORTGClearBits(BIT_14);
	mPORTGClearBits(BIT_15);

	while(1)
	{
		/* Toggle the LEDs sequentially */
		mPORTCToggleBits(BIT_1);
		for(i=0; i<200000; i++); 
		mPORTCToggleBits(BIT_2);
		for(i=0; i<200000; i++); 
		mPORTCToggleBits(BIT_3);
		for(i=0; i<200000; i++);
		mPORTCToggleBits(BIT_4);
		for(i=0; i<200000; i++); 
	
		mPORTGToggleBits(BIT_12);
		for(i=0; i<200000; i++); 
		mPORTGToggleBits(BIT_13);
		for(i=0; i<200000; i++); 
		mPORTGToggleBits(BIT_14);
		for(i=0; i<200000; i++); 
		mPORTGToggleBits(BIT_15);
		for(i=0; i<200000; i++); 
	};

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -