?? motor.c
字號(hào):
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar time,status,percent,period;
bit one_round;
uint oldcount,target=500;
void pulse(void) interrupt 1 using 1
{ TH0=(65536-833)/256; /* 1ms--10MHz */
TL0=(65536-833)%256;
ET0=1;
if (++time==percent) P1=0;
else if (time==100)
{ time=0; P1=1; }
}
void tachometer(void) interrupt 2 using 2
{ union { uint word;
struct {uchar hi;uchar lo;} byte;} newcount;
newcount.byte.hi=TH1;
newcount.byte.lo=TL1;
period=newcount.word-oldcount;
oldcount=newcount.word;
one_round=1;
}
void main(void)
{ IP=0x04; /* set int1 high priority */
TMOD=0x11; /* T0,T1 16-bit mode */
TCON=0x54; /* T0,T1 running, IT1 edge triggered */
TH1=0;TL1=0; /* set initial count */
IE=0x86; /* enable EX1,ET0 */
for(;;)
{ if(one_round)
{ if(period<target)
{ if(percent<100) ++percent;
}
else if(percent>0) --percent;
one_round=0;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -