PIC32MX250F128B 外部発振器なし、FRC利用
* File: main.c
* Author: o
*
* Created on 2014/05/17, 12:56
*/
#include
// DEVCFG2
#pragma config FPLLIDIV = DIV_1
#pragma config FPLLMUL = MUL_20
#pragma config UPLLIDIV = DIV_1
#pragma config UPLLEN = ON
#pragma config FPLLODIV = DIV_2
// DEVCFG1
#pragma config FNOSC = FRC
#pragma config FSOSCEN = OFF
#pragma config IESO = OFF
#pragma config POSCMOD = EC
#pragma config OSCIOFNC = ON
#pragma config FPBDIV = DIV_1
#pragma config FCKSM = CSECMD
int main (void)
{
mSysUnlockOpLock(
{PPSOutput(3, RPA4, REFCLKO);}
);
OSCREFConfig(OSC_REFOCON_FRC,OSC_REFOCON_OE | OSC_REFOCON_ON, 1);
mSysUnlockOpLock(
{OSCCONbits.NOSC = 3; //ECPLL
OSCCONbits.OSWEN = 1;}
);
while(OSCCONbits.COSC != 3);
SYSTEMConfigPerformance(40000000);
// これで、システム40MHz USB48MHz できあがり?
}
ついでに、LEDチカチカ
/*
* File: main.c
* Author:
*
* Created on 2014/05/17, 12:56
*/
#include
#include
#define SYSCLK 40000000L
#define SYSCLKdiv10MHz (SYSCLK/10000000) //ディレイ関数用
// DEVCFG2
#pragma config FPLLIDIV = DIV_1
#pragma config FPLLMUL = MUL_20
#pragma config UPLLIDIV = DIV_1
#pragma config UPLLEN = ON
#pragma config FPLLODIV = DIV_2
// DEVCFG1
#pragma config FNOSC = FRC
#pragma config FSOSCEN = OFF
#pragma config IESO = OFF
#pragma config POSCMOD = EC
#pragma config OSCIOFNC = ON
#pragma config FPBDIV = DIV_1
#pragma config FCKSM = CSECMD
void delay_us(unsigned int usec);
void delay_ms(unsigned int msec);
int main (void)
{
mSysUnlockOpLock(
{PPSOutput(3, RPA4, REFCLKO);}
);
OSCREFConfig(OSC_REFOCON_FRC,OSC_REFOCON_OE | OSC_REFOCON_ON, 1);
mSysUnlockOpLock(
{OSCCONbits.NOSC = 3; //ECPLL
OSCCONbits.OSWEN = 1;}
);
while(OSCCONbits.COSC != 3);
SYSTEMConfigPerformance(40000000);
// これで、システム40MHz USB48MHz できあがり
//System Setting
//SYSTEMConfigPerformance(SYSCLK); //システム最適設定
mJTAGPortEnable(DEBUG_JTAGPORT_OFF); //PORTA is used I/O, JTAG port must be disabled.
mPORTAClearBits( BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0 );
mPORTASetPinsDigitalOut( BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0 );
mPORTBSetPinsDigitalOut( BIT_15 );
ConfigCNBPullups(CNB13_PULLUP_ENABLE);//RB13をプルアップ
mPORTAClearBits( BIT_0 ); //RB5をLowに
mPORTASetPinsDigitalOut( BIT_0 ); //RB5を出力
mPORTASetBits( BIT_15 ); //RB5をHighに
delay_ms(2000); //2秒待機
mPORTAClearBits( BIT_15 ); //RB5をLowに
delay_ms(2000); //2秒待機
while(1)
{
mPORTBToggleBits( BIT_15 ); //RB5の出力状態を反転
if(mPORTBReadBits( BIT_13 )) //RB13の入力状態がhighなら1
delay_ms(500); //0.5秒待機
else
delay_ms(250); //0.25秒待機
}
}
/**********************************