|
請問各位大大們,小弟有一組8051電路,P1.0~P1.2是接三顆感測器(CNY70),兩顆馬達是接P2.0~P2.3
可是當感測器有HI, LO的時候馬達卻沒有動作,請問這是哪裡出問題呢?(假設電路正確)
那程式錯誤在哪裡呢?馬達驅動電路我是用TA7279P(附圖)
#include <reg51.h>
sbit motor1_1=P2^0;
sbit motor1_2=P2^1;
sbit motor2_1=P2^2;
sbit motor2_2=P2^3;
sbit sensor1=P1^0;
sbit sensor2=P1^1;
sbit sensor3=P1^2;
void delay1ms(int);
//=================================
main()
{motor1_1=0;
motor1_2=0;
motor2_1=0;
motor2_2=0;
sensor1=1;
sensor2=1;
sensor3=1;
while(1)
{ if(sensor1==1)
{motor1_1=0;
motor1_2=1;
motor2_1=0;
motor2_2=1;
delay1ms(1000);
if(sensor1==0 )
{motor1_1=1;
motor1_2=0;
motor2_1=0;
motor2_2=1;
delay1ms(1000);
}}
//=================================
void delay 1ms(int x)
{ int i,j;
for (i=0;i<x;i++)
for(j=0;j<120;j++);
}
|
|