|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
外部中断初始化
$ o3 o( B, }. H0 p, R7 d0 } i2 _#include "extint.h"
- Q1 _ j+ @: _1 s+ m//按键和外部中断都用了GPIO13,查询和中断不能同时使用+ @' S( [% @( `) b- S8 N
void InitExtInt(void): j; L7 Y N0 S& v. b
{* R& J3 U( Y9 i7 r2 h- G" w5 t% G
EALLOW;$ A8 |( y% I* z
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
5 l* k3 Z+ w0 I6 T8 [ U& m% i GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //作为输入IO口2 a* x' x# E' ^
GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步# @2 i$ ?! m- z
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
. x- W/ ^( [ ^+ d5 i$ V. LXIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断$ y: o( r6 b% }* H" Q0 K; O7 ]
XIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断
2 S0 {$ e) a* N5 c) Y3 J& wEDIS;. a$ V9 [2 J$ u7 g( |0 i
}' G- E% m* _4 ]7 Z- q6 H5 N+ z
/ M$ v) U3 v- c1 p3 q* a# L. P! e//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
8 K7 x; q. V1 g3 linterrupt void ISRExint1(void)
6 N4 i" _8 T7 Y5 t$ T6 ]! I{
: e) W! J) [4 \% U) V: G PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;; q$ j( j; S3 @( Q \6 Y8 w- F
DELAY_US(1000);
8 {8 v' ?0 g, Kif(GpioDataRegs.GPADAT.bit.GPIO13 == 0)1 }& {; C& |5 R4 f' ]+ s
{; l/ `" ]# k" x% j
LED4=~LED4;+ ]/ e( t V- w5 w9 M# `5 ~ F. N3 }
BUZZ_ON, \# u: Y+ `2 C1 _1 V
DELAY_US(100000);7 R# Q8 n2 a$ A# B( q h
BUZZ_OFF& J2 h1 q7 p$ d
DELAY_US(100000);
" n6 {: ` H$ }. R. h BUZZ_ON
6 P- e3 ]% b/ b, o( T, P DELAY_US(100000);
% s' e) T) z# x4 O" e$ p2 e7 f" T9 L! x BUZZ_OFF
" f* k; c$ Q! s2 \ }
) |+ J6 O! B; G! h5 O}/ c9 S9 G; c, i4 ^* f2 ?/ h
+ R- c S3 X. J4 p* O5 X3 Y3 n- a
1 ?" S5 h' o/ G) D$ b定时器0,1,2中断初始化
5 |8 X! F# X2 g: ^1 m InitCpuTimers(); // For this example, only initialize the Cpu Timers4 h1 e3 R" j( B9 n& A. h$ L
ConfigCpuTimer(&CpuTimer0, 150, 500000); // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)& Z- a! \7 [, D; ]
ConfigCpuTimer(&CpuTimer1, 150, 1000000);
. E5 R/ o; `5 g+ Z# q- ~ ConfigCpuTimer(&CpuTimer2, 150, 3000000);" U6 U t* D' _
StartCpuTimer0();2 w4 d: h( }7 |* U9 _
StartCpuTimer1();
( d3 N" R; v. @7 a4 Z: f5 e StartCpuTimer2();; H: F/ x( S" X5 i* M
! a* j' y' i: c7 i: h
" F7 ?' A! a% i" U! z8 v#include "timer.h"
0 x; B s% S5 _# h$ @' A3 C( ^8 pinterrupt void ISRTimer0(void)% B% Y! T( t$ v6 c) c, c4 U
{
- v' u$ W: I' C static u8 timer0_count=0;6 R+ u0 S) J$ t- e* ^' x: e( y% Y
// Acknowledge this interrupt to receive more interrupts from group 18 |1 v; |8 j( L0 J* f3 r& e( I
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断" N; g9 t6 Z8 s I
CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志 S' p/ k: u% ]6 g
CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
0 z# }6 \, G: X3 n% e/ _0 L9 F! {# y+ p) p$ A
timer0_count++;( Y# ]* p, r5 J! k. P6 T* J
if(timer0_count==4) //2000ms =2s
/ S5 |; h- }/ H- o' l0 B1 Q { a! ]0 w! [6 a; s# K3 H
timer0_count =0;
! {, d/ S! T, n1 l9 L LED1=~LED1;: C( Y- B9 c# `: c) R1 g: V9 f
}
# m; w1 ]* K1 v8 K; g- q( H/ ~4 z}
" ?9 x3 v# S) O/ J# {; s6 Y
/ e) F- l0 i4 v8 o, L/ T* G4 _2 H# L6 v. z* R$ Q( H$ v% B" w
//1s
4 F X. l& g+ A+ r0 s0 U( U5 \interrupt void ISRTimer1(void)6 A4 }& \3 J- ]( g. G S
{
: I8 Z2 X: C; h* }( i% { static u8 timer1_count=0;
% H) W* v2 `0 `1 H// Acknowledge this interrupt to receive more interrupts from group 1
2 U$ m5 D- h! a+ }# L8 x //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
' i2 S7 n& V8 b! B2 R CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
( i7 h6 r. F( s4 e/ d; R1 L CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
4 u7 r& q3 H/ d6 i1 j3 J; ]& x
timer1_count++;0 N" e; J7 [1 u) V% P
if(timer1_count==1)* g- v" @6 H$ `$ M" l1 a+ }
{ l- r$ Z! z& a: w" @- \9 j" { a
timer1_count =0;
9 I9 z z8 N+ e. B' L* y; V& ? LED2=~LED2;
E6 l; F8 h$ A( e( N }- X( t# C2 K4 X$ g
}
6 s& H- }+ y) t9 H4 A
% u+ g7 i+ \) W' j5 T' G9 ^1 ^//3s
1 h. i& }2 b3 C& Y4 Einterrupt void ISRTimer2(void); ?4 p" f" F* H' |& ~
{
1 b9 I# v/ j: {* k7 L static u8 timer2_count=0;0 @4 l7 `8 g) S5 S3 o
// Acknowledge this interrupt to receive more interrupts from group 14 F' c$ A8 i* _: }
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
5 M+ _6 D$ h+ U1 a% ]5 {* R3 W CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
\- q1 ~) I4 j* H2 n4 D CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
( ?& W, i y- f+ i
- V/ u$ Q1 D& B timer2_count++;- l6 S- {/ Q7 y. O8 ]
if(timer2_count==1)0 z ?1 v6 D' j( g6 _" I
{, J7 D4 k% u+ x
timer2_count =0;0 h5 T3 x+ ?3 I+ a( U6 E6 y
//LED3=~LED3;
0 ?/ S: J1 y- S G- ^; j1 h5 k4 P }
( E! I8 K7 d3 X# M$ ~}7 y9 R9 n Y" R
7 @5 R& ^" t2 \8 H; _指定中断服务函数地址
& h% w6 B' @4 r2 H. T0 j, ^5 N EALLOW; // protected registers
/ o8 `6 H9 v; c; `* X+ o PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序+ H/ f* G, |! x' f
PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务
" D7 y I( A7 F& n7 [1 | PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务& K# e) C9 u8 S5 L. w5 a: ?0 Q
PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务
7 j: y8 g4 d- d F6 n; A EDIS; // This is needed to disable write to EALLOW protected registers
6 {( ], H# ]1 ]1 ~4 @7 a# s/ F5 r! P9 ?* \# l
开CPU级中断) x/ G- I0 H& q5 i4 S3 w
IER |= M_INT1; //开启CPU中断 组1
7 k; Z$ ]4 B+ R, a2 M9 H6 I IER |= M_INT13; //开启CPU中断 13 XINT13 / CPU-Timer1
0 k6 o5 t% b2 m' w, _6 L4 Q: J IER |= M_INT14; //开启CPU中断 组14 TINT2
' [+ r# E; l0 _( f7 A/ g/ @7 D/ @
, X# m7 B* x- ?4 V' M9 J# D% { PieCtrlRegs.PIEIER1.bit.INTx7= 1; //CPU定时器 TIMER0中断 组1的第4个中断使能# T, W' S2 h/ G4 |/ X
CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0
# V4 q- ~9 ]5 p4 }% Q CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 07 @- |( m5 V7 ^+ a
- b6 F6 x4 p% y# E7 R EINT; //开启全局中断
4 E+ [/ q1 F8 g# D' O/ d6 w ERTM; //开启全局实时中断,调试用DBGM |
|