📄 motor.c
字号:
#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 T46uS 0x0d00
//#define T46uS 0x0d40
void Delay(unsigned int nTime);
void interrupt time(void);
char ConvertScanToChar(unsigned char cScanCode);
ioport unsigned char port8001;
unsigned int uWork,nCount;
main()
{
unsigned int nSpeed,nScanCode,uWork1;
unsigned char cKey;
int i,j;
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;
nSpeed=T46uS;
TCR = 0x422;
IFR = 0x100;
asm(" rsbx INTM");
for ( i=0;i<10240;i++ )
for ( j=0;j<1024;j++ )
{
nScanCode=port8001;
nScanCode&=0x0ff;
if ( nScanCode!=0 )
{
cKey=ConvertScanToChar(nScanCode);
if ( cKey=='A' )
{
TCR = 0x412;
SPSA0=0;
uWork1=SPSD0;
uWork1&=0xfffe;
SPSD0=uWork1;
SPSA0=0x0e;
uWork1=SPSD0;
uWork1|=0x1101; //set Motor's direction to 1
SPSD0=uWork1;
Delay(512);
PRD=nSpeed;
TCR = 0x422;
}
else if ( cKey=='B' )
{
TCR = 0x412;
SPSA0=0;
uWork1=SPSD0;
uWork1&=0xfffe;
SPSD0=uWork1;
SPSA0=0x0e;
uWork1=SPSD0;
uWork1|=0x1100; //set Motor's direction to 0
uWork1&=0xfffe;
SPSD0=0x1100;//uWork1;
Delay(512);
PRD=nSpeed;
TCR = 0x422;
}
}
}
}
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)
{
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
uWork^=0x4; // FSRP=^FSRP
SPSD1=uWork;
nCount++;
}
char KeyLUT[16]={ 'A','B','C','D',
'E','F','G','H',
'I','J','K','L',
'M','N','O','P'
};
char ConvertScanToChar(unsigned char cScanCode)
{
int nWork;
unsigned int uWork1,uWork2;
uWork1=uWork2=cScanCode;
uWork1>>=4;
uWork2&=0x0f;
switch ( uWork1 )
{
case 1: nWork=0; break;
case 2: nWork=4; break;
case 4: nWork=8; break;
case 8: nWork=12; break;
}
switch ( uWork2 )
{
case 1: nWork+=3; break;
case 2: nWork+=2; break;
case 4: nWork+=1; break;
}
return KeyLUT[nWork];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -