Pokusavam napisati kod za upravljanje steperom u mikroC-u, ali ne radi sve kako treba pa ako moze pomoc oko toga:
Code: Select all
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
char txt1[]="Running";
char txt2[]="Stopped";
void runMotor()
{
TRISB = 0;
PORTB = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1,txt1);
CMCON = 0x07; // To turn off comparators
ADCON1 = 0x06; // To turn off analog to digital converters
TRISD = 0; // PORT D as output port
PORTD = 0x0F;
do
{
PORTD = 0b00000011;
Delay_ms(100);
PORTD = 0b00000110;
Delay_ms(100);
PORTD = 0b00001100;
Delay_ms(100);
PORTD = 0b00001001;
Delay_ms(100);
}while(1);
}
void stopMotor()
{
TRISB = 0;
PORTB = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1,txt2);
CMCON = 0x07; // To turn off comparators
ADCON1 = 0x06; // To turn off analog to digital converters
TRISD = 0; // PORT D as output port
PORTD = 0x0F;
do
{
PORTD = 0b00000000;
Delay_ms(100);
PORTD = 0b00000000;
Delay_ms(100);
PORTD = 0b00000000;
Delay_ms(100);
PORTD = 0b00000000;
Delay_ms(100);
}while(1);
}
void main()
{
runMotor();
TRISC.F0 = 1;
TRISC.F1 = 1;
while(1)
{
if(Button(&PORTC,0,10,0))
{
runMotor();
}
if(Button(&PORTC,1,10,0))
{
stopMotor();
}
}
}
http://i67.tinypic.com/t8qjbk.png
Kad pokrenem simulaciju, motor se pocne okretati, ali kad pritisnem taster za zaustavljanje nista se ne desava, motor se i dalje vrti nakon toga.