|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
外部中断初始化& r- I, b6 Z- ~
#include "extint.h"
! R2 T, f$ G- r//按键和外部中断都用了GPIO13,查询和中断不能同时使用4 b* U& G/ Y8 h2 e* d1 f5 r+ Z9 Y
void InitExtInt(void)! j! n8 ?; L! }/ Y. n
{
6 o/ W8 ?/ B" d% M1 z6 G3 [ EALLOW; _" O" {- F Y4 I2 T& a
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
6 l, z1 C1 j: q- ` GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //作为输入IO口3 z6 ~! M& C- R4 n
GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步
0 i, U7 Y! S) X( ~! O) p0 ~ GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
1 n* z- h y- f# j0 ?9 BXIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断
7 a, R: S( B! RXIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断
5 a# C% f) P6 ^6 \EDIS;9 R, q9 H8 Q7 k/ O* F7 z4 ^
}
I/ O4 d2 H" A; k
: U7 f% u; n6 W) e3 K" B0 M1 B, N//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
# s& _- `% @; U0 k; J" [( d& |$ T' _interrupt void ISRExint1(void)6 h. \ W7 X5 e# z- i
{
. K }& H5 y" o) N) T4 Y3 h PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;# c# l) s! h2 }9 a" R
DELAY_US(1000);5 Q( [! y h9 p" @9 L6 g
if(GpioDataRegs.GPADAT.bit.GPIO13 == 0)
" N5 W% s5 Z8 b{# }) M G$ ^( K" F c
LED4=~LED4;
2 n& T* q& O8 u! b BUZZ_ON1 O2 V1 v4 e# S6 c' E* b
DELAY_US(100000);
& n* r5 j0 Y$ }) |2 v BUZZ_OFF
4 d( |! }' ]4 S DELAY_US(100000);
! `8 ]' }; W! |' x) w/ G2 _9 v BUZZ_ON l1 T) b' d0 U- |5 I0 z
DELAY_US(100000);
- E1 L8 Q, r# y9 x4 [. R BUZZ_OFF
1 u8 X' @; S( ~/ Q% p }
: t Q. W, v$ P& z; F7 {1 f- u2 e}
5 J( v% r6 W) V/ ?( `" o. d! R4 x ?4 o/ j ?1 W. r
+ A- s3 N u$ ]4 x' q! K定时器0,1,2中断初始化
1 n5 o$ i8 b0 R% i0 |& E: V' M3 M6 ? InitCpuTimers(); // For this example, only initialize the Cpu Timers0 B, D. M5 A$ k4 W7 L9 B+ U
ConfigCpuTimer(&CpuTimer0, 150, 500000); // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)& w$ M* |# t; i9 N0 q9 H" z/ L
ConfigCpuTimer(&CpuTimer1, 150, 1000000);1 J0 E5 e6 {) I( v. ~* [' C
ConfigCpuTimer(&CpuTimer2, 150, 3000000);
4 M1 f4 R: X i StartCpuTimer0();
" T2 t; W7 Q! v StartCpuTimer1();. N' f9 f* G7 N1 q
StartCpuTimer2();
\: m4 F& v0 D
- e" y: Z6 q$ L! U8 J/ X: U5 s& w( j/ V
#include "timer.h"
3 q5 O! x2 l4 Ainterrupt void ISRTimer0(void)0 t3 r. \/ ^$ d, C6 U' b
{/ D5 o) X* i" J6 s C. L, s( V1 w
static u8 timer0_count=0;9 |* {- ]4 Y0 v! C: F# G' f4 o! V- A$ d
// Acknowledge this interrupt to receive more interrupts from group 12 G/ f- |4 J# n
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断9 z4 C: R# l c C. C
CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
& d8 u6 X0 c$ e) u6 S CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据2 k* F- c' ^7 @. _! G8 n8 F
: G6 W; A& b: m1 N timer0_count++;& Y+ [5 C4 d/ D+ q. T
if(timer0_count==4) //2000ms =2s
. Q3 F: \* W: W6 O/ y0 `: g$ c {3 Q' B! Y( L0 Q( \" Y" O* q
timer0_count =0;
3 p0 A! _$ k9 X- Q LED1=~LED1;
, L: R" q2 V. W0 |2 [ }% T. C4 S7 t( e8 T( V
}
' d/ m- i3 |, k: z' f* t& W/ ]- ]1 H2 f: N) F) Z
+ z6 V# I3 L4 |4 C& A; i//1s
$ B0 f# u/ O3 t' ?interrupt void ISRTimer1(void)
; C7 K2 J$ f7 j% q3 B! c: h{$ [6 J# w: ]& C0 _( N" I+ ?
static u8 timer1_count=0;
: V& T/ q0 z9 E: d4 V! ]// Acknowledge this interrupt to receive more interrupts from group 14 y8 a" N" m, [- l
//PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断* K: n" @ R, ^" p0 }
CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志8 p" E* q! ^) q* Y
CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
: S: @8 ~- G0 h, z4 M" l% n- O' z& v. A
timer1_count++;
. b3 j+ d& K& U9 I if(timer1_count==1)* z! |3 H f0 j. S0 \
{
' U6 l) V# l2 ~1 T( t& O timer1_count =0;. I) C" D( X8 k, [' R
LED2=~LED2;
$ j6 r& T: `. S- a; E }4 ?$ Z% v/ O9 Q3 |1 L
}" H \: J/ P0 f& m6 E5 [
7 c* v. Y/ y: O, w- b; ~3 r! T) P
//3s
/ @! x/ `6 j4 c( w3 j2 |interrupt void ISRTimer2(void)
9 n& h" B/ I' E2 e4 }! g{% d$ ~9 [% I( v+ ]6 @
static u8 timer2_count=0;
6 g* x2 k7 C$ Q% V8 t" A9 r// Acknowledge this interrupt to receive more interrupts from group 1( {; }7 @, M/ d# y9 X
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断( x Q x( M; e5 X- w) W
CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
, K* Q. W4 @9 w" W, M7 O( t CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据3 S6 ~7 u" a3 G: a
( ?- B* h" l( }* H1 m+ D
timer2_count++;9 {7 m. h- f7 N' v( E& b
if(timer2_count==1)# p: N6 m% f; `2 ?7 U" A
{) ^9 n9 q3 M( f- v( k
timer2_count =0;
. ^5 P7 E% G B9 ?* k) D) w //LED3=~LED3;8 S& \) s- p+ i+ E9 M
}
, @! o4 I7 p' {}
/ j/ |( Q" G$ D$ E/ G, [( D3 @; n% O/ u) \( _
指定中断服务函数地址% e1 @5 F1 y4 k- ?8 ]8 K! Z* q5 C
EALLOW; // protected registers
& Z6 A5 o- v/ T7 E0 x PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序8 \, z- D- Y- n! O* A8 X
PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务8 U; g$ `6 U$ l, ~. ^- D
PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务
, M# ~& L* s+ J% v- i @ PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务
7 Z2 ?+ |! n! d6 ?/ `9 T EDIS; // This is needed to disable write to EALLOW protected registers' P2 _& l0 a$ a. t
7 o6 M+ ~1 m5 o% c( S6 y6 c开CPU级中断
, ~' f" r0 d9 h8 x$ j, y% D IER |= M_INT1; //开启CPU中断 组1
3 `. p, H/ A2 Q6 [ IER |= M_INT13; //开启CPU中断 13 XINT13 / CPU-Timer1
% ^* g; Y+ n( K5 X, T% I IER |= M_INT14; //开启CPU中断 组14 TINT2% R" d5 |8 e+ s b, A1 ^( V
, `3 a+ s: s7 C. ` w) O( J
PieCtrlRegs.PIEIER1.bit.INTx7= 1; //CPU定时器 TIMER0中断 组1的第4个中断使能
, ?. ?* U' Q& b7 e$ c CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0" q# d }" U' O/ I
CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0
% [! p% T5 s; j& [1 l- x8 M8 X8 U X0 g. b) K) D
EINT; //开启全局中断
( |' Y, E# K/ v! r! F ERTM; //开启全局实时中断,调试用DBGM |
|