#include<reg51.h>
#include<stdio.h>
sbit xylanh1 = P0^7;
sbit xylanh2 = P0^6;
sbit dc= P0^5;
//khai bao ham delay
void delay(unsigned int time)
{
while(time--)
{
unsigned char x=121; //cho tha.ch anh 12MHz
while(x--);
}
}
void INT_0(void) interrupt 0 // chuong trinh phuc vu ngat
{
dc=1; //dung dong co
xylanh2=0; //ha tay kep
delay(2500);
xylanh1=0; //kep chi tiet
delay(2500);
xylanh2=1; // nang tay kep
delay(2500);
dc= 0; ///chay dong co
}
void main(void)
{
EA=1; // cho phep ngat toan cuc
EX0=1; // cho phep ngat ngoai 0 (chan P3_2)
IT0=1; //ngat kich phat suon
dc=0; // dong co quay
while(1);
}
#include<stdio.h>
sbit xylanh1 = P0^7;
sbit xylanh2 = P0^6;
sbit dc= P0^5;
//khai bao ham delay
void delay(unsigned int time)
{
while(time--)
{
unsigned char x=121; //cho tha.ch anh 12MHz
while(x--);
}
}
void INT_0(void) interrupt 0 // chuong trinh phuc vu ngat
{
dc=1; //dung dong co
xylanh2=0; //ha tay kep
delay(2500);
xylanh1=0; //kep chi tiet
delay(2500);
xylanh2=1; // nang tay kep
delay(2500);
dc= 0; ///chay dong co
}
void main(void)
{
EA=1; // cho phep ngat toan cuc
EX0=1; // cho phep ngat ngoai 0 (chan P3_2)
IT0=1; //ngat kich phat suon
dc=0; // dong co quay
while(1);
}
Comment