西安电子科技大学继续教育学院毕业论文
}
Fangxiang() {
if(!rotation) {
if(!rotation) { TR0=0; ROT=!ROT; TR0=1; do {}
while(!rotation);
P0=0;
} } }
void Speed1() //速度 { if(!up) {
delay(2); speed=speed+10; } if(!down) {
delay(2);
25
西安电子科技大学继续教育学院毕业论文
speed=speed-10; } }
work() //启停 { if(!run) {
delay(100); if(!run) TR0=!TR0; do{}
while(!run); } } main() { TCON=0; IE=0x82; TMOD=0x01; while(1) { Work(); Speed1(); Fangxiang();
if(ROT==0)
26
西安电子科技大学继续教育学院毕业论文
Z();//正转 else F();//反转 } }
void timer0() interrupt 1 {
TH0=(65535-speed)/255; TL0=(65535-speed)%5; step=++step; delay(1); if(step>=2) step=0; }
测速程序:
#include
#define uchar unsigned char
uchar j,k,i,a,b,sin,A1,A2,A3,aecond; uchar
table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay (uchar i) {
for(j=i;j>0;j--) for(k=125;k>0;k--); }
void display() { P0_0=0;
code
27
西安电子科技大学继续教育学院毕业论文
P1=table[A1]; delay(5); p0_0=1; P0_1=0; P1=table[A2]; delay(5); P0_1=1; P0_2=0; P1=table[A3];
28