|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
外部中断初始化( K& d, o! o' W* j: `: @& U
#include "extint.h"+ p. i& `5 e4 G/ h& ?% j5 X
//按键和外部中断都用了GPIO13,查询和中断不能同时使用) p& X, ?2 s) W0 Q
void InitExtInt(void)# F% e% G* M4 R7 T
{
5 z# m3 X) S# P0 @9 D/ s EALLOW;3 `1 \ {& J: ~5 z1 P& m
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
3 w, B: c# i& U. [+ R6 l, L GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //作为输入IO口: h" k" P' Y* u
GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步0 b; g( g# f$ c8 i9 v) H9 G% ?5 i# P
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
) |" X- q- B: l m( @XIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断4 s: J" ?- |6 I* w
XIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断" K$ A6 h0 P0 ]% h. ]
EDIS;
5 E: k0 |" d) P6 V$ Z}, [ ]9 H6 o: n0 B& e' z( `
% q- _0 l; I# F' V& ` G//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
; W. P! @3 u- a) |5 P: f# binterrupt void ISRExint1(void)
8 w0 u f/ c3 ~/ W3 u3 Q9 p* q{
7 ?) m$ J5 g8 Z9 P5 A$ Z PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;9 @5 t! C+ m" N. Z
DELAY_US(1000);1 r) d B8 B+ F% ]1 m' E# Y, |1 t
if(GpioDataRegs.GPADAT.bit.GPIO13 == 0)
" [ b3 F+ b+ [( X7 A* J. ]' }{
4 h$ O3 {5 j# n0 o* p2 s: [ LED4=~LED4;
* M# [ |1 V5 C9 s( x BUZZ_ON0 k; h$ V5 L3 f; d2 R
DELAY_US(100000);* G9 @1 |4 P n# `( x+ }
BUZZ_OFF7 Y$ B& s! q0 @; \7 {
DELAY_US(100000);$ O3 `1 i d, H3 {9 k( Y
BUZZ_ON
/ [/ c" N4 m: C( Z. a- R# e DELAY_US(100000);
( t/ M3 n! @ \5 B8 K, ~' P BUZZ_OFF2 X) t+ i2 K! V; n
}8 d2 r8 i1 Y: p$ X9 M
}
: Y, f0 B% s7 Y( f3 d
: s9 V) S6 E4 _7 C0 X! E+ E9 y: f( [4 F1 `. l8 I9 O) @5 S
定时器0,1,2中断初始化5 b, a, u( M; G) b
InitCpuTimers(); // For this example, only initialize the Cpu Timers
/ c% Z6 T8 p+ f3 o" l ConfigCpuTimer(&CpuTimer0, 150, 500000); // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)
- t/ v7 Q; r/ a3 O& E ConfigCpuTimer(&CpuTimer1, 150, 1000000);* i: }( m4 p: U9 R
ConfigCpuTimer(&CpuTimer2, 150, 3000000);' v1 U: o! g! O. W
StartCpuTimer0();+ d Q# U6 l1 H# v. m
StartCpuTimer1();
1 b- x: i% u. ~" D0 r StartCpuTimer2();- J8 J( Y3 I- {: c2 B" u
1 @& ?& {; ` j
" Z4 G' U7 O% w# W Z#include "timer.h"& A+ A' G) e2 s& h( S1 V/ y+ X1 `1 n
interrupt void ISRTimer0(void)
T& e: K+ u! D7 r{
, H7 }) o! f+ l$ d static u8 timer0_count=0;2 i( r! S' [' d. P2 ]
// Acknowledge this interrupt to receive more interrupts from group 1$ z' S! w: \+ s; [, D0 U
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断6 C' R: S! }' @& s0 H/ Z2 ^
CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志7 p% r' e+ Z/ q" k/ D% c
CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据1 M* U$ U3 E0 Q% Z: V
. S0 w e+ ]6 B S( g. u timer0_count++;) R) N" ? n/ t% P V$ t- P* W
if(timer0_count==4) //2000ms =2s( H; a2 d. _% F+ `3 X
{
' s- O K, N" u. ~* [8 x0 Q6 v6 F timer0_count =0;, W i" e8 B. Z' c( f/ w% v
LED1=~LED1;
$ p1 Z+ J* r1 f: h3 v5 u }. S' V# y7 h) D
}
6 p9 d. U( u3 @9 J& P" o' G
4 _3 T4 R! C* i- h: R ^% X- e
- ~+ v* y# x+ ~- f" `: D& T9 S//1s
. M5 ~5 ^. b P; K8 Linterrupt void ISRTimer1(void)- U* P1 ^0 m/ p8 S5 S1 H
{7 Z) U5 I4 [. d* i" {
static u8 timer1_count=0;, B0 Z8 z8 s% }9 ]6 y; f
// Acknowledge this interrupt to receive more interrupts from group 1
) |7 D% _/ U, d+ J //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
( L* G. o& k( T% ~& c) B$ S CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志% c T( |- A2 c
CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
! u0 O% H, z7 N" A; | I- G5 q% ^6 i5 t# O4 i% p
timer1_count++;
, d- B3 ^2 m: i if(timer1_count==1)5 Y6 w) w0 s6 ?2 P
{6 v5 N& h5 U# I
timer1_count =0;0 Y4 m& e. y8 [1 o
LED2=~LED2;0 T8 W% q9 y% C) a9 d
}' {3 h5 ~% M6 s# I1 l
}* I) _ s* |2 @6 X' l r
2 s3 b# Q- Z% Z
//3s7 M* P9 B. x, J' M' B
interrupt void ISRTimer2(void)
. _, j; d5 {1 n) }& K% C( B n{! ?8 k( {, v4 j" k5 ?
static u8 timer2_count=0;
& p1 g5 D, G( F% h9 c* N2 Z// Acknowledge this interrupt to receive more interrupts from group 12 [9 K9 W9 z6 d! y( I& M) k1 n
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
$ v; G) F5 d- m7 m CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志 j( n( R1 w* m' b9 R( u; x
CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据* t- _4 b3 o1 G+ v/ ?& r( [9 q6 \
! i# r1 M/ L+ k, }& e8 X# D
timer2_count++;" @0 k1 A% A3 q: S! n
if(timer2_count==1)
* e1 V0 `! h# t* N2 P {) m) p- x4 t5 m4 E/ K/ w# {1 h
timer2_count =0;
' J7 F4 T8 F l5 E Y# C //LED3=~LED3;
7 }2 E% w& }5 [7 Q0 c }
6 Y1 u2 z* a$ C/ c: _$ x}7 l- k, M/ b! Z8 e* u
. @5 o9 R1 |' B) D: r) J
指定中断服务函数地址$ t1 q5 O h4 ]. P
EALLOW; // protected registers
3 `- d2 @( u! M" D- a) ~) M1 L PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序# _6 r5 L& @; V6 B& r
PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务
h3 V$ Y9 a7 s" j8 U9 p& l8 V6 R) c. w PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务
6 Q \. p+ ]. e; [& I PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务5 w% j6 |) u, K6 B4 r8 h
EDIS; // This is needed to disable write to EALLOW protected registers. g3 S# f/ l# S' R& e9 z& \
6 \ S; G' s3 u7 U! I开CPU级中断6 t* |) ^" b. \, R5 X6 }
IER |= M_INT1; //开启CPU中断 组1! n/ g, N- {2 e2 T& Q: \9 K K+ W
IER |= M_INT13; //开启CPU中断 13 XINT13 / CPU-Timer1
5 N4 ?6 }! h; j6 ^- [9 ] IER |= M_INT14; //开启CPU中断 组14 TINT2
1 j4 t3 g5 C8 O0 f
; } k. m0 T. [7 t% N1 X PieCtrlRegs.PIEIER1.bit.INTx7= 1; //CPU定时器 TIMER0中断 组1的第4个中断使能$ c5 T$ a6 g j8 z5 [7 B: v
CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0 L* ]) v$ A7 L! S1 A4 V( N! g& L$ \: }
CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0
" p# k+ ?0 F. u' N
. Q: }; C' u. y2 S- B# d EINT; //开启全局中断3 }3 N8 d! W+ {2 [1 D
ERTM; //开启全局实时中断,调试用DBGM |
|