你从microchip官网上下一些pic32的例程就行啦,各种外设接口的例程都有,下面是定时中断的一个例程。在debug模式下能正常进中断,rd0接口的led闪烁表示芯片是好的#include // configuration bit settings// sysclk = 72 mhz (8mhz crystal/ fpllidiv * fpllmul / fpllodiv)// pbclk = 36 mhz// primary osc w/pll (xt+,hs+,ec+pll)// wdt off// other options are don't care//#pragma config fpllmul = mul_18, fpllidiv = div_2, fpllodiv = div_1, fwdten = off#pragma config poscmod = hs, fnosc = pripll, fpbdiv = div_2// let compile time pre-processor calculate the pr1 (period)#define fosc 72e6#define pb_div 8#define prescale 256#define toggles_per_sec1#define t1_tick (fosc/pb_div/prescale/toggles_per_sec)int main(void){ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //step 1. configure cache, wait states and peripheral bus clock// configure the device for maximum performance.// th** macro sets flash wait states, pbclk divider and drm wait states based on the specified// clock frequency. it also turns on the cache mode if **aialble.// based on the current frequency, the pbclk divider will be set at 1:2. th** knoweldge// ** required to correctly set uart baud rate, timer reload value and other time sensitive// setting.systemconfigperformance(fosc); // override pbdiv to 1:8 for th** timer example moscsetpbdiv(osc_pb_div_8); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // step 2. configure timer 1 using internal clock, 1:256 prescale opentimer1(t1_on | t1_source_int | t1_ps_1_256, t1_tick); // set up the timer interrupt with a priority of 2 configinttimer1(t1_int_on | t1_int_prior_2); // enable multi-vector interrupts intenablesystemmultivectoredint();// configure portd.rd0 = output mportdsetpinsdigitalout(bit_0); while(1);}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // step 3. configure the timer 1 interrupt handlervoid __**r(_timer_1_vector, ipl2) timer1handler(void){ // clear the interrupt flag mt1clearintflag(); // .. things to do // .. in th** case, toggle the led mportdtogglebits(bit_0);} 20210311