cuopbienquin
Joined: 17 Aug 2007 Posts: 4
|
Problem with step |
Posted: Thu Oct 11, 2007 7:46 am |
|
|
I have a problem with control step.Requirement of programing is followed:
1. When press button_direction , directional of rotation of motor is to will change
2.When press button_star/stop, motor turn on or off.
3.while motor is turning , press button_speed1,motor turn speed1
button_speed2,motor turn speed2
This code:
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)
#use fast_io(d)
#byte portb=0x06
#byte portd=0x08
#bit RB0=portb.0
#bit RB1=portb.1
#bit RB2=portb.2
#bit RB3=portb.3
//const unsigned char digital[]={0,1,2};
int i=0; int speed = 0; // ma hoa digital duoi dang mang
// Chuong trinh ngat
#int_ext
void ngat_RB0()
{
while (true)
{
if(RB0==0 )
{
i=(i+1)%3;
}
while (i!=0)
{
//change speed
if ( RB1==0)
{
speed = 50;
}
if ( RB2==0)
{
speed = 25;
}
switch (i)
{
case 1:
portd=0b00000101;
delay_ms(speed);
portd=0b00000001;
delay_ms(speed);
portd=0b00001001;
delay_ms(speed);
portd=0b00001000;
delay_ms(speed);
portd=0b00001010;
delay_ms(speed);
portd=0b00000010;
delay_ms(speed);
portd=0b00000110;
delay_ms(speed);
portd=0b00000100;
delay_ms(speed);
break;
case 2:
portd=0b00000101;
delay_ms(speed);
portd=0b00000100;
delay_ms(speed);
portd=0b00000110;
delay_ms(speed);
portd=0b00000010;
delay_ms(speed);
portd=0b00001010;
delay_ms(speed);
portd=0b00001000;
delay_ms(speed);
portd=0b00001001;
delay_ms(speed);
portd=0b00000001;
delay_ms(speed);
break;
}//end switch
}
//stop
if ( RB3 == 0 )
{
portd = 0;
}
}
}
//
//
main()
{
set_tris_b(0b00000001);
set_tris_d(0);
enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge(H_to_L);
portd=0b00111111;
while(true)
{
}
}
Actually I simulated by Protuess but I only control button_direct and cant control ohter buttons.I hope you correct to me presvious code.Thans and the best lucky for u. _________________ Let shared to be shared. |
|