56 lines
972 B
C
56 lines
972 B
C
// ultrasonic distance sensor
|
|
#include "EXT.h"
|
|
#include "STC15F2K60S2.H"
|
|
#include "displayer.h"
|
|
#include "key.h"
|
|
#include "sys.h"
|
|
#include "universal_decode_table.h"
|
|
|
|
code unsigned long SysClock = 11059200; //必须。定义系统工作时钟频率(Hz),用户必须修改成与实际工作频率(下载时选择的)一致
|
|
char status = 0;
|
|
|
|
void spin1() // 50%
|
|
{
|
|
SetPWM(0, 0, 50, 500);
|
|
LedPrint(8);
|
|
}
|
|
|
|
void spin2() // 30% reverse
|
|
{
|
|
SetPWM(50, 300, 0, 0);
|
|
LedPrint(16);
|
|
}
|
|
|
|
void select()
|
|
{
|
|
char act = GetKeyAct(enumKey1);
|
|
if (act == enumKeyPress)
|
|
{
|
|
if (status == 1)
|
|
{
|
|
spin2();
|
|
status = 0;
|
|
}
|
|
else
|
|
{
|
|
spin1();
|
|
status = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void main()
|
|
{
|
|
EXTInit(enumEXTPWM);
|
|
MySTC_Init();
|
|
DisplayerInit();
|
|
LedPrint(0);
|
|
KeyInit();
|
|
SetEventCallBack(enumKeyPress, select);
|
|
spin1();
|
|
while (1)
|
|
{
|
|
MySTC_OS();
|
|
}
|
|
}
|