|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 cjsb37 于 2013-4-29 09:20 编辑
本人的毕业设计题目是《基于DSP的步进电机控制》,我用的是tms320c5416芯片 是在北京瑞泰公司开发的实验箱上实现的,我现在的程序可以实现步进电机的正反转,但是不能通过键盘输入实现速度控制。望各位大侠指正错误!紧急!!!
程序如下:
#include "scancode.h"
#define TIM *(int *)0x24
#define PRD *(int *)0x25
#define TCR *(int *)0x26
#define IMR *(int *)0x0
#define IFR *(int *)0x1
#define PMST *(int *)0x1d
#define SPSA0 *(unsigned int *)0x38
#define SPSD0 *(unsigned int *)0x39
#define SPSA1 *(unsigned int *)0x48
#define SPSD1 *(unsigned int *)0x49
#define REGISTERCLKMD (*(unsigned int *)0x58)
#define T46uS 0x0fff
void Delay(unsigned int nTime);
void interrupt time(void);
char ConvertScanToChar(unsigned char cScanCode);
ioport unsigned char port8000;
ioport unsigned char port8001;
ioport unsigned char port8002;
ioport unsigned char port8007;
unsigned int uWork,nCount;
unsigned int pwm1[8]={ 0x8e,0x8c,0x8d,0x89,0x8b,0x83,0x87,0x86 };
unsigned int pwm2[8]={ 0x86,0x87,0x83,0x8b,0x89,0x8d,0x8c,0x8e };
int nAddStep,nStep;
main()
{
unsigned int nScanCode,uWork1;
unsigned char cKey;
REGISTERCLKMD=0;
nStep=0; nAddStep=1;
port8000=0; // 初始化ICETEK-CTR
port8000=0x80;
port8000=0;
port8007=0; // 关闭东西方向的交通灯
port8007=0x40; // 关闭南北方向的交通灯
port8007=0x0c2;
uWork1=port8002;
SPSA1=1; // set McBSP1's SPCR2
uWork=SPSD1;
uWork&=0xfffe; // set XRST=0
SPSD1=uWork;
SPSA1=0x0e; // set McBSP1's PCR1
uWork=SPSD1;
uWork|=0x2400; // set XIOEN=1 FSXM=1, Enable IO,FSR for output
SPSD1=uWork;
SPSA0=0; // set McBSP0's SPCR1
uWork=SPSD0;
uWork&=0xfffe; // set RRST=0
SPSD0=uWork;
SPSA0=0x0e; // set McBSP0's PCR1
uWork=SPSD0;
uWork|=0x1101; // set RIOEN=1 FSXM=1, Enable IO,CLKR for output,set Motor's direction to 1
SPSD0=uWork;
uWork1= PMST;
PMST = uWork1&0xff;
IMR = 0x8;
TCR = 0x412;
TIM = 0;
PRD = T46uS;
TCR = 0x422;
IFR = 0x100;
asm(" rsbx INTM");
while ( 1 )
{
if ( nCount>16 )
{
nCount=0;
nScanCode=port8001;
nScanCode&=0x0ff;
uWork=port8002;
if ( nScanCode!=0 )
{
if ( nScanCode==SCANCODE_Enter ) break;
else
{
cKey=ConvertScanToChar(nScanCode);
}
cKey=ConvertScanToChar(nScanCode);
if ( cKey!=0 )
{
if ( cKey=='4' ) nAddStep=1;
else if ( cKey=='6' ) nAddStep=-1;
}
}
}
}
port8007=0x0c0;
}
void Delay(unsigned int nDelay)
{
int i,j,k=0;
for ( i=0;i<nDelay;i++ )
for ( j=0;j<64;j++ )
k++;
}
void interrupt time(void)
{
port8007=pwm2[nStep];
nStep+=nAddStep;
if ( nStep<0 ) nStep=7;
else if ( nStep>7 ) nStep=0;
nCount++;
}
char ConvertScanToChar(unsigned char cScanCode)
{
char cReturn;
cReturn=0;
switch ( cScanCode )
{
case SCANCODE_0: cReturn='0'; break;
case SCANCODE_1: cReturn='1'; break;
case SCANCODE_2: cReturn='2'; break;
case SCANCODE_3: cReturn='3'; break;
case SCANCODE_4: cReturn='4'; break;
case SCANCODE_5: cReturn='5'; break;
case SCANCODE_6: cReturn='6'; break;
case SCANCODE_7: cReturn='7'; break;
case SCANCODE_8: cReturn='8'; break;
case SCANCODE_9: cReturn='9'; break;
}
return cReturn;}
|
|