Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] Re: Weirdness on Butterfly...

2006-04-13 by Cat C

I have another similar problem with my GCC ported butterfly:
I need 4 output pins to eventually control a stepper motor, but for now I'm 
playing just with LEDs.
So first I tried to use PORTB0-3, but only 0, 1 and 2 went HI, and even 
those, not as I expected (not one at a time).
Then I tried PORTF4-7 (this is the code below, exactly as it was for portB, 
just F instead of B).
Almost same thing, except on some outputs the LED is dim when on (looks OK 
with voltmeter) and also not one by one.
I'm pretty sure there's something wrong with my code, or maybe choosing the 
port?
Most of the GCC ported code is still in there, LCD, interrupts (bootloader 
is gone), I just replaced the name tag with my own "stepper code" that for 
now should just cycle through the pins as I move the joystick.
I do get 1, 2, 4, 8 on the LCD... what's wrong?

Thanks,

Cat
char StepperRun(char cLastKey)
{
	DDRF|= (1<<DDF4) | (1<<DDF5) | (1<<DDF6) | (1<<DDF7);

	cbiBF(PORTF,PF4);cbiBF(PORTF,PF6);cbiBF(PORTF,PF5);cbiBF(PORTF,PF7);//make 
them '0'
    LCD_puts_f(PSTR("      "), 1);		//Clear LCD

	while (cLastKey != KEY_PREV)
	{
	if (cLastKey == KEY_PLUS)
	{
		if (iPort_0_3 == 1)
		{
			iPort_0_3 = 2;
			cbiBF(PORTF,PF4);
			sbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
		else if (iPort_0_3 == 2)
		{
			iPort_0_3 = 4;
			cbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			sbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
		else if (iPort_0_3 == 4)
		{
			iPort_0_3 = 8;
			cbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			sbiBF(PORTF,PF7);
		}
		else 		//If it's 8 or anything else
		{
			iPort_0_3 = 1;
			sbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
	LCD_putc(0, '0'+iPort_0_3);	//Put Last Value
	LCD_UpdateRequired(TRUE, 0);
	}
	if (cLastKey == KEY_MINUS)
	{
		if (iPort_0_3 == 8)
		{
			iPort_0_3 = 4;
			cbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			sbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
		else if (iPort_0_3 == 4)
		{
			iPort_0_3 = 2;
			cbiBF(PORTF,PF4);
			sbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
		else if (iPort_0_3 == 2)
		{
			iPort_0_3 = 1;
			sbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			cbiBF(PORTF,PF7);
		}
		else 		//If it's 1 or anything else
		{
			iPort_0_3 = 8;
			cbiBF(PORTF,PF4);
			cbiBF(PORTF,PF6);
			cbiBF(PORTF,PF5);
			sbiBF(PORTF,PF7);
		}
	LCD_putc(0, '0'+iPort_0_3);	//Put Last Value
	LCD_UpdateRequired(TRUE, 0);
	}
	LCD_putc(0, '0'+ iPort_0_3);
	LCD_UpdateRequired(TRUE, 0);
	cLastKey = getkey();
	}
	if (cLastKey == KEY_PREV)
	{
	cbiBF(PORTF,PF4);cbiBF(PORTF,PF6);cbiBF(PORTF,PF5);cbiBF(PORTF,PF7);//make 
them '0'
		return ST_STEPPER;
	}

return ST_STEPPER_RUN;
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.