ai làm về động cơ bước rồi xem giúp em bị sai chỗ nào mà khi em tes mạch thật thì động cơ chỉ giật tại chỗ không có quay gì cả.mục đích của em là cho động cơ quay 1 góc 90° thank các bác nhá
Code:
#include <REGX52.H> sbit chuc1=P0^5; sbit dv1=P0^4; sbit chuc2=P0^7; sbit dv2=P0^6; sbit dc1=P1^0; sbit dc2=P1^1; sbit dc3=P1^2; sbit dc4=P1^3; sbit dc11=P1^4; sbit dc22=P1^5; sbit dc33=P1^6; sbit dc44=P1^7; sbit cb_quang=P0^1; sbit cb_hongngoai=P0^2; sbit cb=P0^0; unsigned char cao,thap; maled[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay_us(int a) { while(--a); } void delay_ms(int b) { while(--b) delay_us(1000); } void hienthi_cao() { unsigned char chuc,dv; chuc=cao/10; dv=cao%10; chuc2=dv2=1; chuc1=1;dv1=0; P2=maled[dv]; delay_ms(3); dv1=1;chuc1=0; P2=maled[chuc];delay_ms(3); } void hienthi_thap() { unsigned char chuc,dv; chuc=thap/10; dv=thap%10; chuc1=dv1=1; chuc2=1;dv2=0; P2=maled[dv]; delay_ms(3); dv2=1;chuc2=0; P2=maled[chuc]; delay_ms(3); } void chaydcthuan() { dc4=1;dc1=0; hienthi_cao(); hienthi_thap(); dc1=1;dc2=0; hienthi_cao(); hienthi_thap(); dc2=1;dc3=0; hienthi_cao(); hienthi_thap(); dc3=1;dc4=0; hienthi_cao(); hienthi_thap(); } void chaydcnguoc() { dc1=1;dc4=0; hienthi_cao(); hienthi_thap(); dc4=1;dc3=0; hienthi_cao(); hienthi_thap(); dc3=1; dc2=0; hienthi_cao(); hienthi_thap(); dc2=1;dc1=0; hienthi_cao(); hienthi_thap(); } void chaydcthuan1() { dc44=1;dc11=0; hienthi_cao(); hienthi_thap(); dc11=1;dc22=0; hienthi_cao(); hienthi_thap(); dc22=1;dc33=0; hienthi_cao(); hienthi_thap(); dc33=1;dc44=0; hienthi_cao(); hienthi_thap(); } void chaydcnguoc1() { dc11=1;dc44=0; hienthi_cao(); hienthi_thap(); dc44=1;dc33=0; hienthi_cao(); hienthi_thap(); dc33=1; dc22=0; hienthi_cao(); hienthi_thap(); dc22=1;dc11=0; hienthi_cao(); hienthi_thap(); } void kiem_tra_cam_bien() { int i; if(cb_quang==0) { cao++; while(cb_quang==0) { for(i=0;i<50;i++) chaydcthuan(); } for(i=0;i<20;i++) { hienthi_cao(); hienthi_thap(); } for(i=0;i<50;i++) chaydcnguoc(); } if(cb==0) { while(cb==0) { for(i=0;i<50;i++) chaydcthuan1(); } for(i=0;i<20;i++) { hienthi_cao(); hienthi_thap(); } for(i=0;i<50;i++) chaydcnguoc1(); } if(cb_hongngoai==0) { thap++; while(cb_hongngoai==0) { hienthi_cao(); hienthi_thap(); } } } void main() { while(1) { kiem_tra_cam_bien(); hienthi_cao(); hienthi_thap(); } }
Comment