共2条
1/1 1 跳转至页
DSP2407 请教DSP2407高手关于定时器1的问题
问
我想利用定时器产生一个在一个周期中有多个脉宽,脉宽是变化的波形,脉宽是预先给定的.我编了个两个脉宽交替变化的程序(用C语言),仿真时用示波器看结果,不管我怎么改变定时器1的周期值,输出波形总是一样的,请问是不什么原因?我把程序贴在下面,请各位大侠帮帮我吧,谢谢!
#include "register.h"
//int T[2]={0x6000,0x8000};
void inline disable( )
{
asm(" setc INTM");
}
void inline enable( )
{
asm(" clrc INTM");
}
initial( )
{
asm(" setc SXM");
asm(" clrc OVM");
asm(" clrc CNF");
*(unsigned int*)SCSR1=0x81FE;
*(unsigned int*)WDCR=0x0E8;
*(unsigned int*)IMR=0x0002;
*(unsigned int*)IFR=0x0FFFF;
*(unsigned int*)WSGR=0x00;
*(unsigned int*)MCRA=*(unsigned int*)MCRA&0x0FF;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR|0x0FF00;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR&0x0FF00;
}
int timer1int( )
{
*(unsigned int*)EVAIMRA=*(unsigned int*)EVAIMRA|0x0080;
*(unsigned int*)EVAIFRA=*(unsigned int*)EVAIFRA|0x0080;
*(unsigned int*)T1CON=0x100C;
*(unsigned int*)T1PR=0x6000;
*(unsigned int*)T1CNT=0x00;
}
void interrupt T1INT( )
{
int flag,i=0,led;
flag=*(unsigned int*)EVAIFRA&0x0080;
if (flag!=0x0080)
{
enable( );
return;
}
i=i+1;
if(i<2)
{
*(unsigned int*)T1PR=0x6000;
led=0x00FE;
}
if (i==2)
{
i=0;
led=0x00FF;
*(unsigned int*)T1PR=0x6000;
}
*(unsigned int*)T1CNT=0x00;
*(unsigned int*)EVAIFRA=*(unsigned int*)EVAIFRA|0x0080;
enable( );
return;
}
void interrupt nothing( )
{
enable( );
return;
}
main( )
{
int led=0x00FF;
disable( );
initial( );
timer1int( );
enable( );
*(unsigned int*)T1CON=*(unsigned int*)T1CON|0x0040;
while(1)
{
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR&0x0FF00;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR|led;
}
}
答 1: ...void interrupt T1INT( ) 中的变量 i ,有什么用,按照理解,你是不是想用全局变量,不然它永远不会是2 答 2: 回复主题:请教DSP2407高手关于定时器1的问题为什么不用PWM来实现呢? 答 3: 同意一楼的。定时器中的变量一般都是全局变量,否则每次进中端之后又从新初始化为0。
#include "register.h"
//int T[2]={0x6000,0x8000};
void inline disable( )
{
asm(" setc INTM");
}
void inline enable( )
{
asm(" clrc INTM");
}
initial( )
{
asm(" setc SXM");
asm(" clrc OVM");
asm(" clrc CNF");
*(unsigned int*)SCSR1=0x81FE;
*(unsigned int*)WDCR=0x0E8;
*(unsigned int*)IMR=0x0002;
*(unsigned int*)IFR=0x0FFFF;
*(unsigned int*)WSGR=0x00;
*(unsigned int*)MCRA=*(unsigned int*)MCRA&0x0FF;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR|0x0FF00;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR&0x0FF00;
}
int timer1int( )
{
*(unsigned int*)EVAIMRA=*(unsigned int*)EVAIMRA|0x0080;
*(unsigned int*)EVAIFRA=*(unsigned int*)EVAIFRA|0x0080;
*(unsigned int*)T1CON=0x100C;
*(unsigned int*)T1PR=0x6000;
*(unsigned int*)T1CNT=0x00;
}
void interrupt T1INT( )
{
int flag,i=0,led;
flag=*(unsigned int*)EVAIFRA&0x0080;
if (flag!=0x0080)
{
enable( );
return;
}
i=i+1;
if(i<2)
{
*(unsigned int*)T1PR=0x6000;
led=0x00FE;
}
if (i==2)
{
i=0;
led=0x00FF;
*(unsigned int*)T1PR=0x6000;
}
*(unsigned int*)T1CNT=0x00;
*(unsigned int*)EVAIFRA=*(unsigned int*)EVAIFRA|0x0080;
enable( );
return;
}
void interrupt nothing( )
{
enable( );
return;
}
main( )
{
int led=0x00FF;
disable( );
initial( );
timer1int( );
enable( );
*(unsigned int*)T1CON=*(unsigned int*)T1CON|0x0040;
while(1)
{
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR&0x0FF00;
*(unsigned int*)PBDATDIR=*(unsigned int*)PBDATDIR|led;
}
}
答 1: ...void interrupt T1INT( ) 中的变量 i ,有什么用,按照理解,你是不是想用全局变量,不然它永远不会是2 答 2: 回复主题:请教DSP2407高手关于定时器1的问题为什么不用PWM来实现呢? 答 3: 同意一楼的。定时器中的变量一般都是全局变量,否则每次进中端之后又从新初始化为0。
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |