📄 torquemotor.c
字号:
/*********************************************************************************************/
/*公司名称:*/
/*模 块 名:力矩电机调试程序*/
/*创 建 人: 日期:2008年8月15日*/
/*功能描述:*/
/*其他说明:当操作P4-P7口时,请别忘了用SFRPAGE寄存器设置为F页。*/
/*********************************************************************************************/
#include "C8051F120.h"
sbit tm1 = P4^6; //箱体力矩电机启动tm1
sbit tmd1= P4^7; //箱体力矩电机方向tmd1
sbit tm2 = P4^4; //箱盖力矩电机启动tm2
sbit tmd2= P4^5; //箱盖力矩电机方向tmd2
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Port_IO_Init()
{
SFRPAGE = CONFIG_PAGE;
P3MDOUT = 0xFF;
P4MDOUT = 0xFF;
P5MDOUT = 0xFF;
P6MDOUT = 0xFF;
P7MDOUT = 0xFF;
XBR0 = 0x04;
XBR2 = 0x44;
}
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
}
void Init_Device(void)
{
Reset_Sources_Init();
Port_IO_Init();
Oscillator_Init();
}
void delay(long t)
{
for(;t>=0;t--);
}
/*
//箱体夹紧电机后退
void tm1cw()
{
tmd1 = 1;
delay(300000);
tm1 = 0;
}
//箱体夹紧电机前进
void tm1ccw()
{
tmd1 = 0;
delay(300000);
tm1 = 0;
}
//箱盖夹紧电机后退
void tm2cw()
{
tmd2 = 1;
delay(300000);
tm2 = 0;
}
//箱盖夹紧电机前进
void tm2ccw()
{
tmd2 = 0;
delay(300000);
tm2 = 0;
}
*/
main()
{
Init_Device();
SFRPAGE = 0x0F;
while(1)
{
tmd1 = 0; //设定箱盖夹紧电机后退方向
delay(600000); //换向后延时
tm1 = 0; //启动箱盖夹紧电机
delay(120000); //延时
tm1 = 1; //箱盖夹紧电机停止运转
delay(600000); //停止后延时
tmd1 = 1; //换向,箱盖夹紧电机前进方向
delay(600000);
tm1 = 0;
delay(120000);
}
/*
delay(6000000); //换向后延时
tm1 = 0; //启动
delay(2000000); //延时
tm1ccw(); //前进
delay(300000);
tm1cw(); //后退
delay(300000);
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -