新建 文本文档.txt
来自「一种使用可控硅控制」· 文本 代码 · 共 246 行
TXT
246 行
全局变量函数库
#include airctrl_private.h
#include airctrl_glob.h
接口函数库
#include airctrl_timer.h
#include airctrl_ledDsply.h
static airctrlTaskData theApp;
static uart_frame uartFrame;
static Objects_timer objectsTimer;
static Tmr_cnt tmrCnt;
uchar display_buffer[5]={5, 4, 3, 2, 1 };
winson_mai
NAME
int1_ISR
DESCRIPTION
中断1子程序
RETURNS
void
void int0_ISR(void) interrupt 2
{
theApp.counter_PGmotor++;
}
winson_mai
NAME
int1_ISR
DESCRIPTION
过零检测中断1子程序
RETURNS
void
void int1_ISR(void) interrupt 0
{
PORT_DMPMTOR = 0;
objectsTimer.glb_moter_8kTimer = objectsTimer.glb_PWM_Counter;
TR1=1; 启动定时器1
ET1=1;
}
void intInit(void)
{
IT0 = 1;
EX0 = 1;
IT1 = 1;
EX1 = 1;
}
主线程
main()
{
static int dulta_speed;
winson init the interface
EA = 0;
intInit();
timerInit();
EA = 1; 打开单片机中断允许
tmrCnt.step = 0;
objectsTimer.glb_PWM_Counter = 56;
objectsTimer.glb_paraPWM_Counter = 10; 1000ms
theApp.setUp_PGmotor = 21;
theApp.speed_PGmotor = 18;
do
{
showbuffer(display_buffer);
if(theApp.flg_showCounter)
{
theApp.flg_showCounter = 0;
display_buffer[1] = ((theApp.speed_PGmotor)1000)%10;
display_buffer[2] = ((theApp.speed_PGmotor)100)%10;
display_buffer[3] = ((theApp.speed_PGmotor)10)%10;
display_buffer[4] = (theApp.speed_PGmotor)%10;
dulta_speed = (theApp.setUp_PGmotor - theApp.speed_PGmotor);
if(dulta_speed 5) 加速
{
objectsTimer.glb_paraPWMchange_Counter = 1; 100ms
theApp.flg_motorDirPP = 0;
}
else if((dulta_speed =5)&&(dulta_speed 2))
{
objectsTimer.glb_paraPWMchange_Counter = 2; 200ms
theApp.flg_motorDirPP = 0;
}
else if((dulta_speed = 2)&&(dulta_speed 1))
{
objectsTimer.glb_paraPWMchange_Counter = 10; 1000ms
theApp.flg_motorDirPP = 0;
}
else if((dulta_speed = 1)&&(dulta_speed = -1))
{
objectsTimer.glb_paraPWMchange_Counter = 11; hold
}
else if((dulta_speed -1)&&(dulta_speed = -2)) 减速
{
objectsTimer.glb_paraPWMchange_Counter = 10; 1000ms
theApp.flg_motorDirPP = 1;
}
else if((dulta_speed -2)&&(dulta_speed = -5))
{
objectsTimer.glb_paraPWMchange_Counter = 2; 200ms
theApp.flg_motorDirPP = 1;
}
else if((dulta_speed -5))
{
objectsTimer.glb_paraPWMchange_Counter = 1; 100ms
theApp.flg_motorDirPP = 1;
}
}
if(objectsTimer.glb_paraPWM_Counter == 0) 调整调制延时
{
objectsTimer.glb_paraPWM_Counter = objectsTimer.glb_paraPWMchange_Counter;
if(theApp.flg_motorDirPP == 0)
{
objectsTimer.glb_PWM_Counter--;
}
else
{
objectsTimer.glb_PWM_Counter++;
}
}
}while(1);
}
void Time1_ISR(void) interrupt 3
{
TH1=0xff;
TL1=0x83;
add your code here.
if(objectsTimer.glb_moter_8kTimer != 0)
{
objectsTimer.glb_moter_8kTimer--;
}
else if(PORT_DMPMTOR == 0)
{
PORT_DMPMTOR = 1;
objectsTimer.glb_moter_8kTimer = 16;
}
else
{
PORT_DMPMTOR = 0;
TR1=0; 启动定时器1
ET1=0;
}
}
winson_mai
NAME
Time0_ISR
DESCRIPTION
定时器中断子程序,实现led动态显示与定时计数器功能(多线程)
RETURNS
void
void Time0_ISR(void) interrupt 1
{
10ms中断
tmrCnt.g_10MsCnt++;
if(objectsTimer.glb_timer != 0)
{
objectsTimer.glb_timer--;
}
100ms中断
if(tmrCnt.g_10MsCnt==10) 100ms
{
g_b100msFlg=1;
tmrCnt.g_10MsCnt=0;
tmrCnt.g_100MsCnt++;
if(objectsTimer.glb_paraPWM_Counter != 0)
{
objectsTimer.glb_paraPWM_Counter--;
}
display the state of damper motor, 500ms
if(tmrCnt.g_100MsCnt%5 ==0 )
{
if(objectsTimer.ledCntr_dmpMtr != 0)
{
objectsTimer.ledCntr_dmpMtr--;
LED_DMPMTOR ^= 1;
}
}
if(tmrCnt.g_100MsCnt==10) 1s
{
g_bSFlg=1;
tmrCnt.g_100MsCnt=0;
tmrCnt.g_second++;
tmrCnt.step++;
电机测试程序
tmrCnt.step = 0;
theApp.speed_PGmotor = theApp.counter_PGmotor;
theApp.counter_PGmotor;
theApp.counter_PGmotor = 0;
theApp.flg_showCounter = 1;
if(tmrCnt.step==2) 1s
{
tmrCnt.step=0;
theApp.speed_PGmotor++;
}
1min中断
if(tmrCnt.g_second==60)1分钟
{
g_bMFl=1;
tmrCnt.g_second=0;
tmrCnt.g_minite++;
1h中断
if(tmrCnt.g_minite==60) 1小时
{
tmrCnt.g_minite=0;
}
}
}
}
TH0=0xd8; 10ms
TL0=0xf0;
ET0=1; 允许定时器0中断
TR0=1;
EA=1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?