Jump to content
firzen91

C2000 Piccolo F28027 Launchpad

Recommended Posts

Hi Everybody;
 
I am newbei about C200O programming with CodeComposerStudio.
I tried simple code which is led blinking.
 
But I want to use button. And I can't run it.
 
Anyway I attached code and screenshot.
 
What's wrong my code?
 

 	GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose);
	GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Input  );

	int state = GPIO_getData(myGpio, GPIO_Number_12);



	GPIO_setLow(myGpio, GPIO_Number_0);
	GPIO_setLow(myGpio, GPIO_Number_1);
	GPIO_setLow(myGpio, GPIO_Number_2);
	GPIO_setLow(myGpio, GPIO_Number_3);


 	while(1)
  {
 		if(state != 1)  {
 				GPIO_setHigh(myGpio, GPIO_Number_0);
 				GPIO_setHigh(myGpio, GPIO_Number_1);
 				GPIO_setHigh(myGpio, GPIO_Number_2);
 				GPIO_setHigh(myGpio, GPIO_Number_3);
 														}

 		else											{
 				GPIO_setLow(myGpio, GPIO_Number_0);
 				GPIO_setLow(myGpio, GPIO_Number_1);
 				GPIO_setLow(myGpio, GPIO_Number_2);
 				GPIO_setLow(myGpio, GPIO_Number_3);
 														}
  }

}

post-32478-0-42502200-1459632804_thumb.png

Share this post


Link to post
Share on other sites

I understand what can I do now?

Because I tried that below code.

 	GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose);
	GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Input  );





	GPIO_setLow(myGpio, GPIO_Number_0);
	GPIO_setLow(myGpio, GPIO_Number_1);
	GPIO_setLow(myGpio, GPIO_Number_2);
	GPIO_setLow(myGpio, GPIO_Number_3);


 	while(1)
  {
 		int state = GPIO_getData(myGpio, GPIO_Number_12);

 		if(state != 1)  {
 				GPIO_setHigh(myGpio, GPIO_Number_0);
 				GPIO_setHigh(myGpio, GPIO_Number_1);
 				GPIO_setHigh(myGpio, GPIO_Number_2);
 				GPIO_setHigh(myGpio, GPIO_Number_3);
 														}

 		else											{
 				GPIO_setLow(myGpio, GPIO_Number_0);
 				GPIO_setLow(myGpio, GPIO_Number_1);
 				GPIO_setLow(myGpio, GPIO_Number_2);
 				GPIO_setLow(myGpio, GPIO_Number_3);
 														}
  }

}

Share this post


Link to post
Share on other sites

I'm not sure if that's the case here, but as written the button might only be read once when the variable is initialized.

 

Try:

int state;

state = read button;

 

Other possible cause:

Is the button on the same GPIO port as the LEDs?

If not, you need a separate myGpio object.

 

Oh, and as you are using CCS, try out it's best feature! You can use debug to step through your program one line at a time and see what's actually happening.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...