|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
外部中断初始化. n4 A& q1 W# s% ]1 B9 i0 N
#include "extint.h"
4 a, {# \- K4 m. @+ A//按键和外部中断都用了GPIO13,查询和中断不能同时使用9 P. c& }5 D4 m& x: j( v
void InitExtInt(void)3 P3 s; X; f: y" l
{
. |9 b0 k8 f, Q; w1 A9 I: n EALLOW;
- o$ ?- ]+ N! M) r' _ GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
I* w2 W; |8 g) m, E$ c$ } GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //作为输入IO口
% @! g3 M# h# S0 M" m( cGpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步" F( ^2 U* Q4 k2 ~* y& Y% H
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
0 X$ t7 l$ ^9 l; b6 h4 S/ w. [XIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断
( s4 w } R3 ^5 n' [XIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断
8 n$ P* B2 d, N5 eEDIS;9 x3 o& B- M9 g& E0 `1 M0 Z
}$ G' f! N5 P+ o
7 m" S8 p9 H- N6 a& i- d; Z
//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
' f: g6 x1 X/ k& Zinterrupt void ISRExint1(void)9 B) ?0 R/ i3 U+ a6 `) N, @6 V
{
) u3 l( i4 I, g2 w! {: w q PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
) Y( ~/ w6 G8 t! QDELAY_US(1000);7 s; ~% V/ D# t/ o
if(GpioDataRegs.GPADAT.bit.GPIO13 == 0)/ e0 V) @- G4 R2 |9 L. S4 ]' z$ ^
{+ [1 C/ s7 o! L4 V8 X
LED4=~LED4;* M- o. S4 L- n4 _" B: m! B( E/ z. `
BUZZ_ON8 p2 i+ ?0 t* V% H
DELAY_US(100000);
! d* J) A+ s( I BUZZ_OFF5 X6 h7 j6 O5 Q5 i2 `
DELAY_US(100000);
" j' j6 C$ s+ I+ ~0 }1 y, I; V BUZZ_ON T8 l9 x1 _' V' P& X5 Z# u
DELAY_US(100000);9 v0 n8 o' P* K
BUZZ_OFF
4 B3 \8 C& Z- A! J7 ]" E }) E7 A- n5 d/ u- V% J- I3 |! m) \
}3 z/ B& y: g* u1 k0 O. f
7 A! w& w3 N& q' K) X" [5 n6 S4 [) D& J+ l# b
定时器0,1,2中断初始化- F2 D5 A9 I# @5 Z4 g
InitCpuTimers(); // For this example, only initialize the Cpu Timers' E, {- S+ v/ H) N$ b$ m. z
ConfigCpuTimer(&CpuTimer0, 150, 500000); // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)
7 E7 w5 B8 W& ]& _& r7 A ConfigCpuTimer(&CpuTimer1, 150, 1000000);$ O9 Y2 L V& A3 Z' l" K$ v/ ]" w
ConfigCpuTimer(&CpuTimer2, 150, 3000000);* x& R, |- B6 J; m( V: Z
StartCpuTimer0();& V' P. q0 R) X1 [: ]6 z6 k
StartCpuTimer1();
+ o7 b- r5 q* l) U6 [ StartCpuTimer2();
6 W( O6 |4 w+ b4 O, E2 M, M6 q: W, V+ Q+ ?0 _
0 s4 [# y7 P% \# I) Q#include "timer.h"
- p* m" d( c, v& [1 l5 Y1 Y* ~2 sinterrupt void ISRTimer0(void)2 W+ \# _: h( R- U7 @# w2 {
{6 p& P: X P7 y# l2 ?! ?2 j, ~
static u8 timer0_count=0;
; d: v8 u7 R% \" z) l# X// Acknowledge this interrupt to receive more interrupts from group 1
! e4 Z9 D X5 ]$ N% K PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
& @) x5 f, e' T2 R% k* O* F. S1 | CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
7 l; k6 u# w& h8 B CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据+ ]; _9 |! @1 ^/ h
+ T6 |5 N4 ]+ m, o timer0_count++;+ ^; b ]$ ~' t3 R. M" L- p
if(timer0_count==4) //2000ms =2s
$ u' |/ I, F/ s8 K, Q {$ }0 \: G' ~. E0 B6 ?
timer0_count =0;
( C' K! [* g8 {$ H LED1=~LED1;
6 a. ~6 ?, {: N4 h }7 d: B4 X- p! X' ]3 R$ c
}! u" s- d5 M' C3 F
1 T& V' |. x+ F7 K+ `; q8 c: f2 p$ C+ ^. L) v& E2 X$ @! F
//1s
! P0 N, N! e9 S( R tinterrupt void ISRTimer1(void)8 Z6 n- F+ N( ~2 S8 y- O0 ^
{) m: N# _) P$ V4 Z. G/ y
static u8 timer1_count=0;7 X2 \/ ?( R$ N/ S* S3 y3 J: k
// Acknowledge this interrupt to receive more interrupts from group 1
2 m6 C; d" S5 O //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
/ ]+ Q& T2 J: ~5 h! ~ CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志% i3 i& _1 F; O: u: @1 A% G
CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
6 S5 y" k, X- e3 h
$ D+ J: }8 K8 s timer1_count++;
! P G( A3 D* w* i if(timer1_count==1)
. r2 r2 p( C! a/ N& m, G$ X& o {% D5 e# F8 A4 U+ h2 v* x0 B8 {- Z
timer1_count =0;
. }1 Z. T+ K: E, ]- g/ b" F% p3 K LED2=~LED2;
( y+ d# O4 l$ A# W% _. c& i }, F$ j) O. Z, r) e i
}
. ]& {' g; B% E# ?) p: l3 W ]6 V6 [* n" }! [' o1 f
//3s5 S( h6 J( `+ s# F: c
interrupt void ISRTimer2(void)7 H6 l4 z9 b4 l4 i' p0 V
{) E5 z& S7 e; ?% t& x. U; p
static u8 timer2_count=0;
; r9 H/ o% M$ x, C// Acknowledge this interrupt to receive more interrupts from group 1
3 Q. X# a) a$ I+ D6 j PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断) h$ a* ]+ ^& b4 \' g A" y
CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志 t3 c! k4 T w: i
CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据$ N# S5 c6 ], `" w
( a0 U. _/ U- |& ]9 b3 g$ x9 r' I timer2_count++;4 D2 r* i, E \- h' U) i; Y) z
if(timer2_count==1)
j. H6 Z2 D0 E; B) D& H {
, Q- |( a7 f5 |% o( Z5 Q. \- m6 u timer2_count =0;9 m) N; s$ J5 d8 r, e3 ], b$ g
//LED3=~LED3;
% g: h0 ^+ ?, ^( w F3 k }
; M. e* h) S) M4 t8 H$ \! z; O( p) ~}% u# S2 s2 o3 u
8 C1 R5 n7 Q6 C, B/ A$ w
指定中断服务函数地址" e: ^& J+ n) m2 I7 t; n6 V( u
EALLOW; // protected registers; _! n- w5 k$ n! ?
PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序
6 l5 C$ U- E" { PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务
: |) }4 f4 [1 I PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务
" g1 V& p2 n4 C* @5 O PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务
; } n! Q* E7 ?+ e& E2 S1 x EDIS; // This is needed to disable write to EALLOW protected registers# z$ ]# ]% X' V" q3 N% i" V
5 ?- }+ v& ?: W! \0 C3 R( a开CPU级中断" Z/ c7 ~1 T6 p4 ?( W' Z1 Y u7 C8 `# i
IER |= M_INT1; //开启CPU中断 组1
1 x8 U" a5 o* k2 A( p1 [ IER |= M_INT13; //开启CPU中断 13 XINT13 / CPU-Timer16 h& j1 B! g$ S* Y9 s
IER |= M_INT14; //开启CPU中断 组14 TINT2. ^ s* \; H2 N- }5 a3 b- W9 U
2 }; r6 q9 r0 p. O5 s PieCtrlRegs.PIEIER1.bit.INTx7= 1; //CPU定时器 TIMER0中断 组1的第4个中断使能: Q0 U" u0 {. z+ q7 Z
CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0
% ?; {! S) D, r! ]* C2 G7 ~/ ? CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0
5 f# p+ o" g; z, H3 y: X* p
) j* Q6 x4 ^1 M4 r$ T' Q' j& _3 J% \ EINT; //开启全局中断6 w/ |, o9 V( Z9 K; F
ERTM; //开启全局实时中断,调试用DBGM |
|