#include // config: production / set config bits // CONFIG3 memória védelem #pragma config WPFP = WPFP511 #pragma config WPDIS = WPDIS #pragma config WPCFG = WPCFGDIS #pragma config WPEND = WPENDMEM // CONFIG2 #pragma config POSCMOD = HS // Primary Oscillator Select (HS oscillator mode selected) #pragma config DISUVREG = ON // Internal USB 3.3V Regulator Disable bit (Regulator is enabled) #pragma config IOL1WAY = ON #pragma config OSCIOFNC = OFF #pragma config FCKSM = CSDCMD #pragma config FNOSC = PRIPLL // Oscillator Select (Primary oscillator +pll ) #pragma config PLL_96MHZ = ON #pragma config PLLDIV = DIV3 // USB 96 MHz PLL Prescaler Select bits (Oscillator input divided by 3 (4MHz input)) #pragma config IESO = OFF // Internal External Switch Over Mode (IESO mode (Two-speed start-up)disabled) // CONFIG1 #pragma config WDTPS = PS32768 #pragma config FWPSA = PR128 #pragma config WINDIS = OFF #pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled) #pragma config ICS = PGx2 // Comm Channel Select (Emulator functions are shared with PGEC2/PGED2) #pragma config GWRP = OFF #pragma config GCP = OFF #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled) #define BYTE unsigned char #define BOOL unsigned char #define FALSE 0 #define TRUE 1 // delay. meg kell adni a cpu clock-ot #define SYS_FREQ 32000000L #define FCY SYS_FREQ/2 #include // ledek, gombok #define LED1 LATGbits.LATG6 #define LED2 LATGbits.LATG7 #define LED3 LATGbits.LATG8 #define LED4 LATGbits.LATG9 #define LEDR LATDbits.LATD15 #define LEDG LATFbits.LATF4 #define LEDB LATFbits.LATF5 #define SW1 !PORTCbits.RC1 #define SW2 !PORTCbits.RC3 #define SW3 !PORTEbits.RE8 #define SW4 !PORTEbits.RE9 void __attribute__((__interrupt__,__auto_psv__)) _T3Interrupt(void) { LED1=!LED1; IFS0bits.T3IF=0; // bitet törölni } void __attribute__((__interrupt__,__auto_psv__)) _T1Interrupt(void) { LEDB=!LEDB; IFS0bits.T1IF=0; // bitet törölni } BYTE i,on; // memóriában, mint byte int main(void) { // PLL start, osccon CLKDIVbits.CPDIV=0; // 32 mhz while (!OSCCONbits.LOCK) Nop(); // megvártuk az indulást OSCCONbits.SOSCEN=1; __builtin_write_OSCCONL(OSCCON | 1<<1); // bit 1 set int dbg=OSCCON; Nop(); Nop(); Nop(); // led tris. gombnál default az input TRISGbits.TRISG6=0; // 0: output TRISGbits.TRISG7=0; TRISGbits.TRISG8=0; TRISGbits.TRISG9=0; TRISDbits.TRISD15=0; TRISFbits.TRISF4=0; TRISFbits.TRISF5=0; i=0; // LEDR=1; on=0; // timer3 1 sec belsö, 1:256, 62500 pr PR3=62500; T3CONbits.TCKPS=0b11; // 1:256 T3CONbits.TON=1; // timer be IPC2bits.T3IP=1; // 1-es prior alacsony IFS0bits.T3IF=0; // töröld le IEC0bits.T3IE=1; // jöhet // timer1 1 sec küls? órajel, 32768-as pr PR1=0x8000; T1CON=0x8002; // 1:1, küls?, on IPC0bits.T1IP=2; // fontosabb IFS0bits.T1IF=0; IEC0bits.T1IE=1; // engedd. while (1) { if (SW2) { on^=1; LED2=on; Sleep(); // aludj. Timer1 majd felébreszt __delay_ms(50); while (SW2) Nop(); // felengedést vár __delay_ms(50); } if (SW3) { __asm__ volatile ( "reset "); } // LED1^=1; // xor //__delay_ms(1000); Nop(); } // feladat: LED1..LED4 futófény, SW2 iránya. switch! return 0; }