|
#include <reg52.h>
#include <intrins.h>
sbit KEY_UP=P1^3;
sbit KEY_DW=P1^4;
sbit DIR_UP=P3^2;
sbit DIR_DW=P3^3;
sbit CON_ECU=P3^4;
void DelayUs2x(unsigned char t);
void DelayMs(unsigned char t);
void Delay_ms(unsigned char t);
void main()
{
KEY_UP=1;
KEY_DW=1;
DIR_UP=0;
DIR_DW=0;
CON_ECU=1;
while(1)
{
if(KEY_UP==0)
{
Delay_ms(5);
if(KEY_UP==0)
{
CON_ECU=0;
Delay_ms(10);
DIR_UP=1;
DelayMs(10);
CON_ECU=1;
Delay_ms(10);
DIR_UP=0;
DelayMs(190);
DIR_DW=1;
Delay_ms(10);
DIR_DW=0;
}
}
if(KEY_DW==0)
{
DelayMs(10);
if(KEY_DW==0)
{
DIR_DW=1;
Delay_ms(10);
DIR_DW=0;
DelayMs(190);
DelayMs(190);
DelayMs(190);
DIR_UP=1;
Delay_ms(10);
DIR_UP=0;
}
}
}
}
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
void Delay_ms(unsigned char t)
{
unsigned char i,j,k;
for(k=0;k<t;k++)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
看這個(gè) 我想改成觸發(fā)一次電機(jī)就只轉(zhuǎn)一次 如果這個(gè)信號一直維持也只轉(zhuǎn)設(shè)定的那幾十毫秒,再次觸發(fā)同樣,怎么搞啊 |
|