trienst
10-11-2012, 03:16 AM
em đang thực hiện mô phỏng động cơ bước, chỉ đơn giản là dùng bảng dịch trạng thái động cơ bước điều khiển nửa bước
code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>
#include<delays.h>
#pragma config WDT = OFF, OSC = HS
void main()
{
TRISC=0x00;
PORTC=0x00;
TRISD=0xff;
while(1)
{
if(PORTDbits.RD0==0){
PORTC=0x10;
Delay10TCYx(2);
PORTC=0x50;
Delay10TCYx(2);
PORTC=0x40;
Delay10TCYx(2);
PORTC=0x60;
Delay10TCYx(2);
PORTC=0x20;
Delay10TCYx(2);
PORTC=0xa0;
Delay10TCYx(2);
PORTC=0x80;
Delay10TCYx(2);
PORTC=0x90;
Delay10TCYx(2);
}
//cambio di rotazione
if(PORTDbits.RD1==0){
PORTC=0x90;
Delay10TCYx(2);
PORTC=0x80;
Delay10TCYx(2);
PORTC=0xa0;
Delay10TCYx(2);
PORTC=0x20;
Delay10TCYx(2);
PORTC=0x60;
Delay10TCYx(2);
PORTC=0x40;
Delay10TCYx(2);
PORTC=0x50;
Delay10TCYx(2);
PORTC=0x10;
Delay10TCYx(2);
}
}
}
nhưng động cơ ko chạy, trễ khi nhấn nút rất nhiều, mong mọi người giúp đỡ
code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>
#include<delays.h>
#pragma config WDT = OFF, OSC = HS
void main()
{
TRISC=0x00;
PORTC=0x00;
TRISD=0xff;
while(1)
{
if(PORTDbits.RD0==0){
PORTC=0x10;
Delay10TCYx(2);
PORTC=0x50;
Delay10TCYx(2);
PORTC=0x40;
Delay10TCYx(2);
PORTC=0x60;
Delay10TCYx(2);
PORTC=0x20;
Delay10TCYx(2);
PORTC=0xa0;
Delay10TCYx(2);
PORTC=0x80;
Delay10TCYx(2);
PORTC=0x90;
Delay10TCYx(2);
}
//cambio di rotazione
if(PORTDbits.RD1==0){
PORTC=0x90;
Delay10TCYx(2);
PORTC=0x80;
Delay10TCYx(2);
PORTC=0xa0;
Delay10TCYx(2);
PORTC=0x20;
Delay10TCYx(2);
PORTC=0x60;
Delay10TCYx(2);
PORTC=0x40;
Delay10TCYx(2);
PORTC=0x50;
Delay10TCYx(2);
PORTC=0x10;
Delay10TCYx(2);
}
}
}
nhưng động cơ ko chạy, trễ khi nhấn nút rất nhiều, mong mọi người giúp đỡ