EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1046|回复: 0

[转帖] DSP28335定时器和外部输入中断

[复制链接]

106

主题

13

回帖

96

E币

助理工程师

Rank: 3Rank: 3

积分
225
发表于 2018-11-28 16:15:56 | 显示全部楼层 |阅读模式
外部中断初始化; o, l' U* H2 L1 V& g
#include "extint.h"
//按键和外部中断都用了GPIO13,查询和中断不能同时使用, {. T- _$ }/ [8 X6 @9 [$ f7 S' \
void InitExtInt(void)
{3 Q  ?, E- V& m6 \+ s8 i
     EALLOW;3 K% I) m& G3 ]. n0 ^
     GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
     GpioCtrlRegs.GPADIR.bit.GPIO13 = 0;           //作为输入IO口' q5 T# E/ \+ J& \  |5 a
GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0;          //和时钟同步0 w/ j+ g: x& a6 B9 t# T/ _  d
     GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13;    //选择GPIO13为外部输入XINT1输入引脚6 g$ F* o% _9 L" P# l) ~5 o
XIntruptRegs.XINT1CR.bit.POLARITY= 0;         //下降沿触发中断
XIntruptRegs.XINT1CR.bit.ENABLE = 1;          //使能XINT1中断
EDIS;9 G. E1 J& f/ b& @
}% Z0 \9 d4 k2 C& v. w! T

//外部中断1服务函数  ,按下按键,进中断,亮灯响鸣4 |/ s$ c8 N3 @2 D% d
interrupt void ISRExint1(void)
{# {" B$ M1 E! y
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;9 N' n5 t2 \% d( j  w
DELAY_US(1000);/ Q; F# [( ^+ j! ]7 C
if(GpioDataRegs.GPADAT.bit.GPIO13 == 0). p: P* p, s! M' @! _& S
{: p3 Q, Y- r' ]% y) _# U: O2 T" l
    LED4=~LED4;
    BUZZ_ON
    DELAY_US(100000);' ^  [: ?& m3 f: u
    BUZZ_OFF
      DELAY_US(100000);
    BUZZ_ON
    DELAY_US(100000);2 P" ~( _* ?6 U5 G2 z3 o9 X7 e
    BUZZ_OFF& {/ W: M5 m0 Z( a4 ^' m$ X) Y, r
    }4 ^4 d! a7 C7 u( X# }
}

1 |& E: L) g/ Q& P- V
定时器0,1,2中断初始化
    InitCpuTimers();   // For this example, only initialize the Cpu Timers
    ConfigCpuTimer(&CpuTimer0, 150, 500000);  // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)5 n6 E% q* s" m$ R$ _9 G/ Z
    ConfigCpuTimer(&CpuTimer1, 150, 1000000);; G+ i6 u; [3 }
    ConfigCpuTimer(&CpuTimer2, 150, 3000000);: n& O' H6 G5 D( Z. ~- T7 z
    StartCpuTimer0();
    StartCpuTimer1();
    StartCpuTimer2();
$ Y& B6 \; s$ k5 C: H

#include "timer.h"
interrupt void ISRTimer0(void)% \" n! f( q: P8 [% E' r2 U
{! s) G6 P; C% }( k. g6 i
    static u8 timer0_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
    CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
    CpuTimer0Regs.TCR.bit.TRB=1;  // 重载Timer0的定时数据6 j' r& n! a, Y
9 l. w" e- z  P9 @2 Y
    timer0_count++;
    if(timer0_count==4)  //2000ms =2s
    {
    timer0_count =0;! Y  ?' E) ?# y5 X
    LED1=~LED1;
    }: G0 s# c* |$ Q9 {. C
}# P; S) p( ^. j9 |9 d
# Y# V+ l  E8 F# O6 T

//1s
interrupt void ISRTimer1(void)+ R3 m( H& W$ t* T2 z! E" w# W: d
{
    static u8 timer1_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
    //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断$ r8 P$ a$ {) [- ]6 B4 a
    CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
    CpuTimer1Regs.TCR.bit.TRB=1;  // 重载Timer0的定时数据0 d3 ^6 S8 f) _1 Y( J) k; M

    timer1_count++;( I8 l9 _+ F* a' M0 u
    if(timer1_count==1)
    {
    timer1_count =0;
    LED2=~LED2;& X4 a6 o- o( _- N
    }1 F' }/ O: [! ~6 N
}

//3s
interrupt void ISRTimer2(void)
{
    static u8 timer2_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
    CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志9 W* F+ |# g* P& L$ o, x" d* t2 Z
    CpuTimer2Regs.TCR.bit.TRB=1;  // 重载Timer0的定时数据
9 Q) h- n- p: Q1 w9 h
    timer2_count++;7 q- _9 y% g. m  S) k! D% c' h
    if(timer2_count==1)$ s1 H* u$ o6 J6 a; W% o
    {6 ]: ~/ x/ T/ E0 }) @/ O- l
    timer2_count =0;
    //LED3=~LED3;' L3 e: b. B; B; w7 ?$ k) Z: s
    }
}
0 `& K. D3 M8 i5 E* H, ~
指定中断服务函数地址
     EALLOW;  //  protected registers, ?5 C0 \1 E% X# A1 M" Y0 X/ C
    PieVectTable.XINT1 = &ISRExint1;  //外部中断1服务程序
    PieVectTable.TINT0 = &ISRTimer0;   //定时器0中断服务" W: d& m% }- L( ~
    PieVectTable.XINT13 = &ISRTimer1;   //定时器1中断服务: i. J( C+ m# F
    PieVectTable.TINT2  =  &ISRTimer2;    //定时器2中断服务6 x( O8 S+ p/ Q3 b; ~4 t- t6 X, y4 y
    EDIS;    // This is needed to disable write to EALLOW protected registers
5 d" o( F: W) R) {/ s
开CPU级中断* P. M0 L# T+ M; H
    IER |= M_INT1;    //开启CPU中断 组1
    IER |= M_INT13;   //开启CPU中断 13   XINT13 / CPU-Timer1
    IER |= M_INT14;   //开启CPU中断 组14 TINT2
    7 {& @8 f7 x! C* [* [
    PieCtrlRegs.PIEIER1.bit.INTx7= 1;  //CPU定时器 TIMER0中断   组1的第4个中断使能
    CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0+ O$ A" j3 v! v2 ?  v
    CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0; }: G2 W0 D# c, ~3 I+ R% ^( @' ?1 ~

    EINT;   //开启全局中断9 A/ z1 s& O! O4 S- i0 D! k$ L* B
    ERTM;   //开启全局实时中断,调试用DBGM


积分规则
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-4-20 19:28 , Processed in 0.045531 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表