?? torquemotor.c
字號:
/*********************************************************************************************/
/*公司名稱:*/
/*模 塊 名:力矩電機調試程序*/
/*創(chuàng) 建 人: 日期: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 + -