void labinit( void ) { *trisE &= ~0xff; *portE = 0; TRISD |= 0xfe0; // T2CONSET = 0x8070; //enable timer2 with 1:256 PR2 = 31250; //set counter // enable timer2 interrupt and global interrupt IPCSET(2) = 0x1f; //priority IECSET(0) = 0x100; //timer2 enable //SW3 IPCSET(3) = 0x1f; //SW3 priority IECSET(0) = 0x8000; //SW3 enable interrupt //enable all interrupts enable_interrupt(); return; }
/* * Setup core timer for `hz' timer interrupts per second. */ void clkstart() { unsigned count = mips_read_c0_register (C0_COUNT, 0); mips_write_c0_register (C0_COMPARE, 0, count + (CPU_KHZ * 1000 / HZ + 1) / 2); IECSET(0) = 1 << PIC32_IRQ_CT; }
/* * Initialize USB module SFRs and firmware variables to known state. * Enable interrupts. */ void usbinit() { usb_device_init(); IECSET(1) = 1 << (PIC32_IRQ_USB - 32); #if !defined(USB_AUTOBOOT) /* Wait for any user input. */ while (! cdc_consume(0)) #endif usb_device_tasks(); }
/* Lab-specific initialization goes here */ void labinit( void ) // Enable interrupts from Timer 2 { volatile unsigned int* trise = (unsigned int*) 0xbf886100; *trise = *trise & ~0xff; // It's possible to use TRISDSET here as well but then it wouldn't be defined // if the bits not in use are 0 or 1. TRISDCLEAR can be used to clear specific // bits without affecting other bits. TRISDSET = 0x7f << 5; T2CON = 0x0; // Stop timer2 T2CONSET = 0x0070; // Prescale 1:256 Surprise: change 256 to 32 (7 -> 5) TMR2 = 0; // Timer2 value starts at 0 PR2 = 31250; // Timer2 value ticks to a suitable number IPC(2) = 1 << 2; // Set priority to 2, sub priority to 3 // We enable interrupts to check the time-out event-flag. IECSET(0) = 0x0100; // Enable Timer 2 interrupt enable_interrupt(); // Enable interrupts globaly T2CONSET = 0x8000; // Start timer2 return; }