#include //#include #pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = ON //USB Voltage Regulator #pragma config WDT = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = ON #pragma config LPT1OSC = OFF #pragma config PBADEN = OFF //#pragma config CCP2MX = ON #pragma config STVREN = ON #pragma config LVP = OFF //#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF #pragma config CP1 = OFF //#pragma config CP2 = OFF //#pragma config CP3 = OFF #pragma config CPB = OFF //#pragma config CPD = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF //#pragma config WRT2 = OFF //#pragma config WRT3 = OFF #pragma config WRTB = OFF // Boot Block Write Protection #pragma config WRTC = OFF //#pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF //#pragma config EBTR2 = OFF //#pragma config EBTR3 = OFF #pragma config EBTRB = OFF #define _XTAL_FREQ 48000000 //__delay_ms #define SW1 PORTEbits.RE0 #define SW2 PORTEbits.RE1 #define LED PORTEbits.RE2 int n; void init(void) { ADCON1 = 0b00001111; TRISA = 0b00000000; TRISB = 0b00000000; TRISC = 0b00110000; //D-,D+ TRISD = 0b00000000; TRISE = 0b00000011; //SW1,2=INPUT LED=OUTPUT LATA = 0b00000000; LATB = 0b00000000; LATC = 0b00000000; LATD = 0b00000000; LATE = 0b00000000; } void main(void) { init(); n = 20; while(1) { for ( int i = 0; i < n; i++ ) __delay_ms( 10 ); //10mS LED = !LED; if(SW2 == 0) { n = n+1; if (n >= 40) { n = 1; } } if(SW1 == 0) { n = n-1; if (n <= 0) { n = 40; } } } }