|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
外部中断初始化! U& }8 R' B4 n ~- z( J5 L' M
#include "extint.h"
8 r3 L9 A! H# T//按键和外部中断都用了GPIO13,查询和中断不能同时使用
4 F' V, a3 W( t" l# ]. W; p( _void InitExtInt(void), [! _! M* `! c4 X% v5 H, y" Z
{
) w6 @6 ~* B! R4 a EALLOW;$ c" o% Q9 y& O5 |, i8 d5 g4 `
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;6 c4 a- g: U4 h# z' D: i* [
GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //作为输入IO口
! @# u, o/ m9 a2 _6 ]; _GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步
1 k, q5 J+ I+ T3 r/ d GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
8 W& ~* J' m8 A5 gXIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断
8 h- y$ z' ~) e7 }XIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断7 w3 L& ~$ [4 F" c) u/ J3 ]
EDIS;
2 G- W3 o+ q, V* H2 T' I}
7 g. D6 i H' i5 I
6 [3 k( |+ V% r9 ?) ]//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
0 T; C. g Q: ginterrupt void ISRExint1(void)
/ e1 i# C, b2 N3 O{1 I4 g' B6 _" R9 B& l+ Y
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;& `2 f9 h; j: F& o- W) B5 ]" N
DELAY_US(1000);
# B& I+ g7 @, Xif(GpioDataRegs.GPADAT.bit.GPIO13 == 0)% g r3 z% Q7 z+ N2 F7 N$ F
{& H4 W0 U8 T+ j3 l! S
LED4=~LED4;
5 \; r* @! X4 d/ J" j% o BUZZ_ON
3 k. R# p/ x) W! B% ~9 H1 @ DELAY_US(100000);) _$ [% h9 ]% H( a
BUZZ_OFF
( I% ]/ k; R# j9 T DELAY_US(100000);8 {+ F+ B$ Z( a, \, T5 V/ W
BUZZ_ON$ S. B% s0 |: {" X5 D7 b
DELAY_US(100000);% O% T: O' f# D) V/ n1 N
BUZZ_OFF6 i% V+ ?$ o( G6 e6 @; d. R% f
}
2 [* F+ B3 r+ ^( ~" i+ D}# W/ y9 y. A1 D1 G. W
" R( A& S1 Y; ^; Z" T' E( j5 y8 U, ~
/ N) x, A% b) u# U, C定时器0,1,2中断初始化* ?3 ~ U8 t; d" [0 t: a
InitCpuTimers(); // For this example, only initialize the Cpu Timers
4 ]+ w7 L: O0 ~7 J$ w ConfigCpuTimer(&CpuTimer0, 150, 500000); // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)
# q+ J, Q& E9 x7 M2 H2 G7 J5 `0 e ConfigCpuTimer(&CpuTimer1, 150, 1000000);+ ~$ t) A& }* t# L
ConfigCpuTimer(&CpuTimer2, 150, 3000000);
( `! y5 H5 c4 \4 f$ |! V R8 Z" o6 v StartCpuTimer0();% [* G, `$ u) f
StartCpuTimer1();, i0 m4 ~" P0 t1 f
StartCpuTimer2();
& I$ u/ k. p2 C; I9 F4 T" Z+ [& t
, b# m# e' r7 j/ r0 k; K#include "timer.h"
- ]3 T7 ?+ D( K W- k# Ointerrupt void ISRTimer0(void) _: u% o, `% d' p+ L
{
, k! T$ f) J. `3 L static u8 timer0_count=0;
6 n9 }+ O3 Q9 t: O. s// Acknowledge this interrupt to receive more interrupts from group 1
; b$ ?" I, b5 l0 Z ` PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
4 Q& C D0 W9 z5 O, k* {, d CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志9 G0 ?3 d9 e& X& L+ Y
CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据% v- F: {0 h/ K0 f( L2 y7 a* i/ V) {! @
& ~' l$ L" W: w7 a; u0 f, N3 I
timer0_count++;
& s1 p, w; ~2 `! }- y! V" n if(timer0_count==4) //2000ms =2s
# H) ^$ U$ C& _5 R% { {
% o" w4 g0 s* @" j$ W- X& I timer0_count =0;0 d2 G' W, S/ @% ]% U+ h) N0 Q" p
LED1=~LED1;7 J4 u1 P4 H1 |' d0 w& c
}8 I: h) N$ j2 {# P: c8 a+ J7 n
}
# o0 S! o: D8 Z) x# y1 P4 r( C
* M! s$ R( o1 R6 i% w+ O$ l) p, r
, L0 d6 k- k: ~; K+ f//1s5 ]: [3 g& [" Y0 e& u! ]
interrupt void ISRTimer1(void)! ]& r; z6 c0 s, m
{
7 c; H/ [& Q- F: K static u8 timer1_count=0;
+ s6 |7 D3 g+ ~* k- n" t// Acknowledge this interrupt to receive more interrupts from group 16 z* A0 {" Z; J a1 S+ m* q
//PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
' T: w; _$ [7 Q, h. y1 M5 s# N6 ~; F CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
2 Y4 b5 K4 `/ u1 V6 B1 [ CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据2 ?" o; {% r" _" m, r+ v
% {7 F i7 c5 [/ O! r! c0 M
timer1_count++;6 L$ }2 ~0 w2 g: }/ h: K8 j+ [( P, B
if(timer1_count==1)
& r3 n/ Y* o4 T* U% G4 i% n {
; r/ m+ K. K5 M( R/ Y- s$ ~1 y timer1_count =0;
6 e1 L9 F, `9 T; ?1 S0 A' k LED2=~LED2;
. Z1 F0 Y9 @1 L }
' @0 R' o- A y5 Y3 k}3 z( d+ q7 m9 x6 ]! F
7 t6 }9 {6 _2 Z& c4 |+ x' G//3s
. w! E; D$ I! t2 o$ c# Winterrupt void ISRTimer2(void)* i& x9 _ I; }0 j
{
- i8 I$ a4 Y, s* O/ u4 j static u8 timer2_count=0;; r" x" u' c! W3 L D* g! m! y7 A5 [
// Acknowledge this interrupt to receive more interrupts from group 1
: J6 J! l+ t2 S8 D5 e PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
1 u* U: G+ @& ^! \* s CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志% I& }2 R$ `+ R: B ]
CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据0 c3 R0 c, ^, \, ]
# l f2 v5 Q5 k3 F5 d- I9 V
timer2_count++;6 Z" a6 z! Y& x0 V% g l+ @
if(timer2_count==1)
; w. F8 U3 J* I8 { { {
) E4 ^! C3 w" x* {) ^ timer2_count =0;
0 ~2 ^0 v) c: y5 n- X //LED3=~LED3;
+ ~- F9 a2 E, v4 R4 l1 p }9 W8 u# V6 q2 D* Y# J7 |! x6 V$ S
}
5 G6 [9 Q9 d, w0 g/ e U1 _6 {+ @# X2 a8 ^4 T* s
指定中断服务函数地址
7 M4 v, @8 n T# ^3 t* e EALLOW; // protected registers
4 l4 G+ a( s" v. A) L PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序
6 E! {. m- h! h0 _9 P- [ PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务3 {% x0 w* r, f& T) M. [0 I
PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务
( N4 P5 y' n& Q% U$ k7 i1 ^3 [, E PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务4 A# J6 R/ p; F4 C. _
EDIS; // This is needed to disable write to EALLOW protected registers
2 z, f% i# z2 }' T- _7 G1 U
( @9 \5 l! b! f: s开CPU级中断; j1 b0 K# u7 x- P9 L: }
IER |= M_INT1; //开启CPU中断 组1+ f& Q4 Y1 v+ C5 T
IER |= M_INT13; //开启CPU中断 13 XINT13 / CPU-Timer18 v2 C- S: p, {& S
IER |= M_INT14; //开启CPU中断 组14 TINT2- q3 w* L. o- U' j8 Z
$ p; A: }- L Z1 L
PieCtrlRegs.PIEIER1.bit.INTx7= 1; //CPU定时器 TIMER0中断 组1的第4个中断使能$ Z: u* x y8 {; D1 W9 h
CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0
1 z0 s/ F5 \+ ?& V Q; Z+ ] CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0
8 Z2 Y9 F9 \* g. u
% o8 y8 H, s P' s/ u, u% ?; x$ N EINT; //开启全局中断
) T- p4 a) q7 I ERTM; //开启全局实时中断,调试用DBGM |
|