_init(void); // Main Program void main(void) { // Initialize System Control: InitSysCtrl(); // Initialize GPIO: gpio_init(); // Initialize Timer: InitCpuTimers(); // Configure CPU-Timer 0 to interrupt every 500 milliseconds: ConfigCpuTimer(&CpuTimer0, 150, 1000000); // Start CPU-Timer 0 StartCpuTimer0(); // Enable global Interrupts and higher priority real-time debug events: IER |= M_INT1; EINT; // Perform the first action immediately GpioDataRegs.GPBDAT.bit.GPIO68 = 1; // Main loop while(1) { if(timer_int_cnt % 4 == 0) // Every 2 seconds { // Toggle the GPIO68 LED GpioDataRegs.GPBTOGGLE.bit.GPIO68 = 1; } else if(timer_int_cnt % 6 == 0) // Every 3 seconds { // Toggle the GPIO66 LED GpioDataRegs.GPBTOGGLE.bit.GPIO66 = 1; } else if(timer_int_cnt % 8 == 0) // Every 4 seconds { // Toggle the GPIO64 LED GpioDataRegs.GPBTOGGLE.bit.GPIO64 = 1; } } } // Initialize GPIO void gpio_init(void) { // Init the GPIO pins for LEDs: EALLOW; GpioCtrlRegs.GPBDIR.bit.GPIO68 = 1; GpioCtrlRegs.GPBDIR.bit.GPIO66 = 1; GpioCtrlRegs.GPBDIR.bit.GPIO64 = 1; GpioDataRegs.GPBDAT.bit.GPIO68 = 0; GpioDataRegs.GPBDAT.bit.GPIO66 = 0; GpioDataRegs.GPBDAT.bit.GPIO64 = 0; EDIS; } // CPU Timer 0 Interrupt Service Routine interrupt void cpu_timer0_isr(void) { // Acknowledge the interrupt PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Increment the interrupt count timer_int_cnt++; } interrupt void cpu_timer1_isr(void) { // Acknowledge the interrupt PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Increment the interrupt count timer_int_cnt++; } interrupt void cpu_timer2_isr(void) { // Acknowledge the interrupt PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Increment the interrupt count timer_int_cnt++; } [2024-10-20 21:14:21 | AI写代码神器 | 1312点数解答]