Có Bác nào biết về Điều Khiển ĐC Rc Servo bang 8051 ko vào xem hộ em cái code này đúng hay sai vs
Mã code
#include<reg52.h>
#include<stdio.h>
#include <intrins.h>
sbit motor_pin = P1^0;
sbit b0 =P3^0;
sbit b45 =P3^1;
sbit b90 =P3^2;
sbit b135 =P3^3;
sbit b180 =P3^4;
void delay(unsigned ms)
{
while (ms--)
{
TMOD=0x01; //dùng timer 0 che^' ðo^. 1 ( 16bit )
TH0=0xfc;
TL0=0x18; //hai câu le^.nh na.p giá tri ðe^'m
TR0=1; // cho phép timer 0 hoa.t ðo^.ng
while (TF0); //cho+` TF0=1(co+` tràn =1 )
TF0=0; //xóa co+` tràn
TR0=0; // ngu+`ng Timer
}
}
void main(){
motor_pin = 1;
if(b0 == 0){
motor_pin = 1;
delay(20); //0
//delay(89); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
if(b45 == 0){
motor_pin = 1;
delay(30); //45
//delay(89); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
if(b90 == 0){
motor_pin = 1;
//delay(30); //45
//delay(89); //180
delay(48); // 90
motor_pin =0;
delay(910);
}
if(b135 == 0){
motor_pin = 1;
//delay(30); //45
//delay(89); //180
delay(70); // 135
motor_pin =0;
delay(910);
}
if(b180 == 0){
motor_pin = 1;
//delay(30); //45
delay(87); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
}
Mã code
#include<reg52.h>
#include<stdio.h>
#include <intrins.h>
sbit motor_pin = P1^0;
sbit b0 =P3^0;
sbit b45 =P3^1;
sbit b90 =P3^2;
sbit b135 =P3^3;
sbit b180 =P3^4;
void delay(unsigned ms)
{
while (ms--)
{
TMOD=0x01; //dùng timer 0 che^' ðo^. 1 ( 16bit )
TH0=0xfc;
TL0=0x18; //hai câu le^.nh na.p giá tri ðe^'m
TR0=1; // cho phép timer 0 hoa.t ðo^.ng
while (TF0); //cho+` TF0=1(co+` tràn =1 )
TF0=0; //xóa co+` tràn
TR0=0; // ngu+`ng Timer
}
}
void main(){
motor_pin = 1;
if(b0 == 0){
motor_pin = 1;
delay(20); //0
//delay(89); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
if(b45 == 0){
motor_pin = 1;
delay(30); //45
//delay(89); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
if(b90 == 0){
motor_pin = 1;
//delay(30); //45
//delay(89); //180
delay(48); // 90
motor_pin =0;
delay(910);
}
if(b135 == 0){
motor_pin = 1;
//delay(30); //45
//delay(89); //180
delay(70); // 135
motor_pin =0;
delay(910);
}
if(b180 == 0){
motor_pin = 1;
//delay(30); //45
delay(87); //180
//delay(48); // 90
motor_pin =0;
delay(910);
}
}