📄 isr.c
字号:
//*******************************************************************//
//Interrupt Service Routine For C language
//*******************************************************************//
#include "car.h"
#include "s480.h"
//#include "tlv2543.h"
__asm(".external F_FIQ_Service_SACM_S480");
extern unsigned long int codetime;
extern unsigned int codenum;
extern unsigned int time_ms,time1;
extern unsigned int ceshi;
extern unsigned char sent_flag;
extern unsigned long int motor_step,step_num,motor0_num,motor0_time,motor1_time,motor1_num,time,timer;
extern unsigned char motor0_en,motor0_step,motor1_step,motor1_en,s0_flag,s1_flag,stepmode;
extern unsigned int index;
extern unsigned int dif_index;
extern float VOL[10], dif_VOL[10];
extern float voltage;
void BREAK(void) __attribute__ ((ISR));
void BREAK(void)
{
}
void FIQ(void) __attribute__ ((ISR));
void FIQ(void)
{
if(*P_INT_Ctrl&C_FIQ_TMA)
{
*P_INT_Clear=C_FIQ_TMA;
__asm("call F_FIQ_Service_SACM_S480");
if(motor0_en)
{
motor0_time++;
motor_step++;
if(motor0_time>motor0_num)
{ if(stepmode)
{
step_num--;
if(step_num==0)
{
motor0_en=0;
motor1_en=0;
stepmode=0;
}
}
switch(motor0_step)
{
case 0:
if(s0_flag==0)
{
a0=1;
b0=0;
c0=0;
d0=0;
}
else
{
a0=0;
b0=0;
c0=0;
d0=1;
}
break;
case 1:
if(s0_flag==0)
{
a0=1;
b0=1;
c0=0;
d0=0;
}
else
{
a0=0;
b0=0;
c0=1;
d0=1;
}
break;
case 2:
if(s0_flag==0)
{
a0=0;
b0=1;
c0=0;
d0=0;
}
else
{
a0=0;
b0=0;
c0=1;
d0=0;
}
break;
case 3:
a0=0;
b0=1;
c0=1;
d0=0;
break;
case 4:
if(s0_flag==0)
{
a0=0;
b0=0;
c0=1;
d0=0;
}
else
{
a0=0;
b0=1;
c0=0;
d0=0;
}
break;
case 5:
if(s0_flag==0)
{
a0=0;
b0=0;
c0=1;
d0=1;
}
else
{
a0=1;
b0=1;
c0=0;
d0=0;
}
break;
case 6:
if(s0_flag==0)
{
a0=0;
b0=0;
c0=0;
d0=1;
}
else
{
a0=1;
b0=0;
c0=0;
d0=0;
}
break;
case 7:
a0=1;
b0=0;
c0=0;
d0=1;
break;
default:break;
}
motor0_time=0;
motor0_step++;
if(motor0_step>7)
motor0_step=0;
}
}
if(motor1_en)
{
motor1_time++;
if(motor1_time>motor1_num)
{
switch(motor1_step)
{
case 0:
if(s1_flag==0)
{
a1=1;
b1=0;
c1=0;
d1=0;
}
else
{
a1=0;
b1=0;
c1=0;
d1=1;
}
break;
case 1:
if(s1_flag==0)
{
a1=1;
b1=1;
c1=0;
d1=0;
}
else
{
a1=0;
b1=0;
c1=1;
d1=1;
}
break;
case 2:
if(s1_flag==0)
{
a1=0;
b1=1;
c1=0;
d1=0;
}
else
{
a1=0;
b1=0;
c1=1;
d1=0;
}
break;
case 3:
a1=0;
b1=1;
c1=1;
d1=0;
break;
case 4:
if(s1_flag==0)
{
a1=0;
b1=0;
c1=1;
d1=0;
}
else
{
a1=0;
b1=1;
c1=0;
d1=0;
}
break;
case 5:
if(s1_flag==0)
{
a1=0;
b1=0;
c1=1;
d1=1;
}
else
{
a1=1;
b1=1;
c1=0;
d1=0;
}
break;
case 6:
if(s1_flag==0)
{
a1=0;
b1=0;
c1=0;
d1=1;
}
else
{
a1=1;
b1=0;
c1=0;
d1=0;
}
break;
case 7:
a1=1;
b1=0;
c1=0;
d1=1;
break;
default:break;
}
motor1_time=0;
motor1_step++;
if(motor1_step>7)
motor1_step=0;
}
}
///////////////////////////////////////////////
}
if(*P_INT_Ctrl&C_FIQ_PWM)
*P_INT_Clear=C_FIQ_PWM;
if(*P_INT_Ctrl&C_FIQ_TMB)
*P_INT_Clear=C_FIQ_TMB;
}
void IRQ0(void) __attribute__ ((ISR));
void IRQ0(void)
{
}
void IRQ1(void) __attribute__ ((ISR));
void IRQ1(void)
{
*P_INT_Clear=0x1000;
/*codetime++;
if(sent_flag)
{
if(codetime==2000)
*P_IOB_Data|=0x0001; //将IOB0置1
if(codetime==5900)
{
*P_IOB_Data&=0xfffe; //将IOB0置0
codetime=0;
codenum++;
}
}*/
}
void IRQ2(void) __attribute__ ((ISR));
void IRQ2(void)
{
}
void IRQ3(void) __attribute__ ((ISR));
void IRQ3(void)
{
}
void IRQ4(void) __attribute__ ((ISR));
void IRQ4(void)
{
if(*P_INT_Ctrl&C_IRQ4_1KHz)
{
*P_INT_Clear=0x0010;
time_ms++;
time++;
timer++;
if(*P_ADC_MUX_Ctrl&C_LINEIN_RDY)
{
*P_ADC_MUX_Ctrl=C_ADC_MUX_IOA3;
voltage=(*P_ADC_LINEIN_Data>>6);
voltage*=(3.0/1024);
VOL[index] = voltage;
index++;
if(index==10)index=0;
dif_VOL[dif_index]=VOL[index-1]-VOL[index];
dif_index++;
if(dif_index==10) dif_index=0;
}
*P_Watchdog_Clear=1;
}
if(*P_INT_Ctrl&C_IRQ4_2KHz)
*P_INT_Clear=0x0020;
*P_Watchdog_Clear=1;
if(*P_INT_Ctrl&C_IRQ4_4KHz)
{
*P_INT_Clear=0x0040;
*P_Watchdog_Clear=1;
}
}
void IRQ5(void) __attribute__ ((ISR));
void IRQ5(void)
{
}
void IRQ6(void) __attribute__ ((ISR));
void IRQ6(void)
{
}
void IRQ7(void) __attribute__ ((ISR));
void IRQ7(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -