#include //#include //#include #pragma config PLLDIV = 5 // Divide by 5 (20 MHz oscillator input) #pragma config CPUDIV = OSC1_PLL2 //[Primary Oscillator Src: /1][96 MHz PLL Src: /2] #pragma config USBDIV = 2 // USB clock source comes from the 96 MHz PLL divided by 2 #pragma config FOSC = HSPLL_HS //HS oscillator, PLL enabled (HSPLL) #pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled #pragma config IESO = OFF //Fail-Safe Clock Monitor disabled #pragma config PWRT = OFF //PWRT disabled #pragma config BOR = ON //Brown-out Reset enabled in hardware only (SBOREN is disabled) #pragma config BORV = 3 //Minimum setting #pragma config VREGEN = ON //USB voltage regulator enabled #pragma config WDT = OFF //[Watchdog Timer Enable] disabled (control is placed on the SWDTEN bit) #pragma config WDTPS = 32768 //Watchdog Timer Postscale Select bits 1:32768 #pragma config MCLRE = ON //MCLR pin enabled; RE3 input pin disabled #pragma config LPT1OSC = OFF //Timer1 configured for higher power operation #pragma config PBADEN = OFF //PORTB<4:0> pins are configured as digital I/O on Reset //#pragma config CCP2MX = ON #pragma config STVREN = ON //Stack full/underflow will cause Reset #pragma config LVP = OFF //Single-Supply ICSP disabled //#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF //Block 0 (000800-001FFFh) is not code-protected #pragma config CP1 = OFF //Block 1 (002000-003FFFh) is not code-protected //#pragma config CP2 = OFF //#pragma config CP3 = OFF #pragma config CPB = OFF //Boot block (000000-0007FFh) is not code-protected //#pragma config CPD = OFF #pragma config WRT0 = OFF //Block 0 (000800-001FFFh) is not write-protected #pragma config WRT1 = OFF //Block 1 (002000-003FFFh) is not write-protected //#pragma config WRT2 = OFF //#pragma config WRT3 = OFF #pragma config WRTB = OFF // Boot block (000000-0007FFh) is not write-protected #pragma config WRTC = OFF //Configuration registers (300000-3000FFh) are not write-protected //#pragma config WRTD = OFF #pragma config EBTR0 = OFF //Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks #pragma config EBTR1 = OFF //Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks //#pragma config EBTR2 = OFF //#pragma config EBTR3 = OFF #pragma config EBTRB = OFF //Boot block (000000-0007FFh) is not protected from table reads executed in other blocks #define _XTAL_FREQ 48000000 //__delay_ms #define SW1 PORTEbits.RE0 #define SW2 PORTEbits.RE1 #define LED PORTEbits.RE2 unsigned short n; unsigned char CH[4] = { 0x01,0x02,0x04,0x08}; void init(void) { ADCON1 = 0b00001111; //全チャンネルがデジタルに設定され、VDDとVSSが選択 TRISA = 0b00011100; //A0〜A4を入力に設定 TRISB = 0b00000000; //出力に設 TRISC = 0b00110000; //D-,D+(USB用)RC4とRC5を入力に設定 TRISD = 0b00000000; //D0〜D7を出力に設定 TRISE = 0b00000011; //SW1,2=INPUT LED=OUTPUT LATA = 0b00000000; LATB = 0b00000000; LATC = 0b00000000; LATD = 0b00000000; LATE = 0b00000000; } void main(void) { int i; init(); n = 1000; while(1) { for(i=0;i<10;i++){__delay_ms( 2 );} //20mS LED = !LED; if(SW1 == 0) { n = n+1; } if(SW2 == 0) { n = n-1; } PORTD=CH[n % 4]; } }