Current location - Education and Training Encyclopedia - Graduation thesis - Design of stepping motor control system based on single chip microcomputer
Design of stepping motor control system based on single chip microcomputer
# include & ltreg 5 1 . h & gt;

# Define uchar unsigned characters

uchar stepd[]={0x0 1,0x03,0x02,0x06,0x04,0xc0,0x08,0x 09 };

uchar num=0,FX = 0;

sbit key 1=p3^0;

sbit key2=p3^ 1;

sbit key3=p3^2;

Void t0isr () interrupt 1

{

TH0 =(65536- 10000)/256;

TL0 =(65536- 10000)% 256;

P2 = stepd[ number];

if(FX = = 0){ num++; num % = 8; }

if(fx== 1)

{

if(num = = 0)num = 7;

else num-;

}

}

Master ()

{

TMOD = 0x 0 1;

TH0 =(65536- 10000)/256;

TL0 =(65536- 10000)% 256;

TR0 = 1;

ET0 = 1;

EA = 1;

while( 1)

{

if(key 1==0)

{

while(key 1 = = 0);

TR0 = ~ TR0

}

if(key2==0)

{

while(key 2 = = 0);

FX = 0;

}

if(key3==0)

{

while(key 3 = = 0);

FX = 1;

}

}

}