Thursday, 5 March 2015

DC Motor AT89S52

#include<reg52.h>
sbit sw1=P0^0;
sbit sw2=P0^1;
sbit m1p=P0^2;
sbit m1n=P0^3;
sbit m2p=P0^4;
sbit m2n=P0^5;
void msdelay(unsigned int);
void main()
{
while(1)
{
if(sw1==1&&sw2==0)
m1p=0;
m1n=1;
msdelay(200);
if(sw1==0&&sw2==1)
m2p=1;
m2n=0;
msdelay(200);
}
}
void msdelay(unsigned int item)
{
unsigned int i,j;
for(i=0;i<item;i++)
for(j=0;j<1275;j++);
}

No comments:

Post a Comment