UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor vccy1188
Visitor
11,149 Views
Registered: ‎05-18-2010

Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution

Hi, I am new to SDK and I am trying to implement a C program to control the LEDs on Spartan 3E starter kit via the 4 switches on the board.

 

I already did the XPS hardware part but I have no idea how to do the software part.

 

I read the documents but cannot find how to assign pins, LED variables, etc.

 

Any help will be highly appreciated!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
14,326 Views
Registered: ‎08-02-2007

Re: Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution

Here is the example.

 

Please make sure that you have Pushbuttons and LED's in your system.

 

#include "xgpio.h"
#include "xparameters.h"

int main(void)
{
   XGpio gpLED;
   XGpio gpPB;

   // Initialise the peripherals
   XGpio_Initialize(&gpLED, XPAR_LEDS_4BIT_DEVICE_ID);
   XGpio_Initialize(&gpPB, XPAR_PUSHBUTTONS_5BIT_DEVICE_ID);

   // Set the LED peripheral to outputs
   XGpio_SetDataDirection(&gpLED, 1, 0x00000000);

   // Set the Push Button peripheral to inputs
   XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);

   Xuint32 data = 0;

   while(1)
   {
      // Read the state of the push buttons
      data = XGpio_DiscreteRead(&gpPB, 1);

      // Set the LED state
      XGpio_DiscreteWrite(&gpLED, 1, data);
   }
}

 

Thnx

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
5 Replies
Xilinx Employee
Xilinx Employee
14,327 Views
Registered: ‎08-02-2007

Re: Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution

Here is the example.

 

Please make sure that you have Pushbuttons and LED's in your system.

 

#include "xgpio.h"
#include "xparameters.h"

int main(void)
{
   XGpio gpLED;
   XGpio gpPB;

   // Initialise the peripherals
   XGpio_Initialize(&gpLED, XPAR_LEDS_4BIT_DEVICE_ID);
   XGpio_Initialize(&gpPB, XPAR_PUSHBUTTONS_5BIT_DEVICE_ID);

   // Set the LED peripheral to outputs
   XGpio_SetDataDirection(&gpLED, 1, 0x00000000);

   // Set the Push Button peripheral to inputs
   XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);

   Xuint32 data = 0;

   while(1)
   {
      // Read the state of the push buttons
      data = XGpio_DiscreteRead(&gpPB, 1);

      // Set the LED state
      XGpio_DiscreteWrite(&gpLED, 1, data);
   }
}

 

Thnx

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
Highlighted
Newbie gemcalvin
Newbie
10,514 Views
Registered: ‎07-18-2011

Re: Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution
im a student and i need vhdl code for controlling switches and LEDs on spartan 3E starter kit. any code will do, easy or moderate is better because im just new in this field.. thank you in advance..
Tags (2)
0 Kudos
Teacher eteam00
Teacher
10,510 Views
Registered: ‎07-21-2009

gemcalvin, promising young student?

Jump to solution

@gemcalvin,

 

im a student and i need vhdl code for controlling switches and LEDs on spartan 3E starter kit.

 

What is the point of being a student if you do not attempt to complete your own assignments?  Do your courses teach VHDL?  If you are having problems with following the course material, you should consult your instructor.

 

Do you agree?

 

-- Bob Elkind

SIGNATURE:
README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:
1. Read the manual or user guide. Have you read the manual? Can you find the manual?
2. Search the forums (and search the web) for similar topics.
3. Do not post the same question on multiple forums.
4. Do not post a new topic or question on someone else's thread, start a new thread!
5. Students: Copying code is not the same as learning to design.
6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).
7. You are not charged extra fees for comments in your code.
8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.
0 Kudos
10,014 Views
Registered: ‎05-10-2012

Re: Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution

can i please get the hardware specifications?

 

Tags (1)
0 Kudos
Historian
Historian
9,994 Views
Registered: ‎02-25-2008

Re: Any sample C code for controlling switches and LEDs on Spartan 3E starter kit?

Jump to solution

@prasaduna4847 wrote:

can i please get the hardware specifications?

 


Hardware specs for what?

 

A 1/4-20 screw's hardware specs are:

1/4" diameter.

20 threads per inch.

----------------------------Yes, I do this for a living.
0 Kudos