You are here

LED Blinky | Cypress Semiconductor

LED Blinky

Last Updated: 
Mar 18, 2012

Project Introduction:

For this example project, which we will playfully call ‘LED Blinky’, the CY8CKIT-001 hardware will be used to control an LED by toggling a push button switch. This example will assume that you’ve completed the initial ‘PSoC Rocks!’ example project that instructed the user on creating new projects and discussed the basic layout of the software tool.

This example project focuses on taking an input, in this case a button push, and redirecting that input as an output, or flashing LED. The relationship of inputs to outputs is fundamental to all embedded systems and will be introduced in this example project. We will continue to build on this theme throughout the PSoC Designer example projects.

Software Used:

PSoC Designer: Click Here
PSoC Programmer: Click Here

Hardware Used:

This example project will utilize the following hardware.

All of the above hardware is included in the CY8CKIT-001 kit.

Steps to Set Up Hardware:

To set up this hardware please perform the following actions:

  • Insert the CY8CKIT-020 processor module into the CY8CKIT-001 socket.
  • Connect a wire to the black bread board headers from SW1 to P0_0
  • Connect a wire to the black bread board headers from LED1 to P1_0

Please see the wires connected in the image below. The wires are represented by the red lines and must be connected to the black headers running next to white bread board. The CY8CKIT-001 is shipped with a set of wires. Each wire has an exposed end. This exposed end must be inserted into the header. Each header whole has silk screening on the board that indicates the routing. If the header hole indicates P0_0, then this means that the header is routed to the port 0 pin 0 pin on the PSoC. The bottom black header indicates connections to components that are on the target board. For example the LED1 header hole will connect directly to the LED1. The wires allow us to physically connect a pin on the PSoC to a component on the board and use them in our embedded design.

Steps to Create Project

This example project assumes that you’ve completed the ‘PSoC Rocks!’ introductory example project. The ‘PSoC Rocks!’ example project walks the user through project creation and the software layout. It’s suggested to complete that example before completing this example project. To begin this example project create a new project using PSoC Designer.

  1. Open PSoC Designer by navigating Start -> All Programs -> Cypress -> PSoC Designer -> PSoC Designer. This will launch the PSoC Designer application.
  2. In the Recent Projects window at the top left please select the New Project… link.
  3. In the New Project window please enter in the name of the project “CY8C28445_LED_Blinky”. Please select the project location by selecting the Browse button. Click OK
  4. The Select Project Type window will open. You can either click the drop down menu to select the target device or launch the device catalog by clicking the View Catalog button. We will be selecting the “CY8C28445-24PVXI” device.
  5. If you select the parts via the View Catalog option then please scroll down to the “CY8C28445-24PVXI” device and select the Select button.
  6. You will return to the Select Project Type window. Please select the “C” radio button for main.c file generation. This will mean that you will be developing a C-based project rather than an assembler based project. Select OK.

After you select the OK button PSoC Designer will open the Chip Editor view. In the following section we will cover the various options and actions available in the Chip Editor view. We will begin setting parameter values and designing our system.

User Module Placement and Configuration

In this section we will discuss how to design the embedded system by setting global parameters for the PSoC and making pin selections. In this example we will not use any user modules.

  1. In this example project will need to configure our pin selections to read the button state and use that state to control a output to drive an LED. Please navigate to the Pinout window in the Chip Level Editor.


  2. Select the “+” button on Pin P0(0) and click on the Drive row. To the right a drop down menu will appear. From the available selections please select Pull Up. Here we are setting up our pin parameters to read in the state from the button.


  3. Scroll down and select the “+” button on Pin P1(0) From the available drive mode selections please select Strong. This parameter will allow us to drive the output on P1(0) and control the LED.


  4. Now that all of the pin selections are complete we need to generate the project source files based on our selections. Please navigate to the menu panel and select the Generate Configuration Files button. The output window will display the actions when generating the configuration files and report any design rule check (DRC) warnings.

Now that we have completed the Pinout selections and configuration we will proceed to add source code to our embedded project.

Adding Source Code

When generating the project we selected C language development. We will now add our C code to the main.c file.

  1. Navigate to the Workspace Explorer window, expand the source files directory and double-click the main.c file.


  2. The main.c file is now open in the editor tab window. Users will notice that the Workspace Explorer is still available on the right side and can scroll between the text editor and the Chip Editor. Users can open additional files by double-clicking files in the Workspace Explorer.

  3. We will now add source code to our project to enable the button and the LED controls. The code is linked below and should be added into the main function.

    void main( void )
    while ( 1 )
    if (PRT0DR & 0x01 ) //Checks the state of the button. If the button is pressed then it will execute.

    PRT1DR &= ~ 0x01 ; //Turns the LED On.
    PRT1DR |= 0x01 ; //Turns the LED Off.


  4. Once the code has been entered into the main.c file we will build the project by selecting Build>Generate/Build, pressing F6, or by selecting the Build button from the menu bar .
  5. The build status will be displayed in the Output window. The output window will display either a successful build or a list of build errors associated with the project. In this case we will have no build errors.
  6. Make sure that the Miniprog3, included in the CY8CKIT-001 kit, is connected to the white 5-pin programming connector to the USB port on the PC.
  7. To program our target device please select Program>Program Part. This will launch the PSoC Designer embedded programmer. Please choose the Power Cycle radio button and then select the Program button, which is located at the bottom right of the embedded programmer.


  8. Now that the device is programmed we want to power the CY8CKIT-001 and see the message displayed on the LCD screen. To do this keep the Embedded Programmer open and select the Toggle Power button.
  9. Next, test your projects functionality. When you press the SW1 button the LED should come on. When the button is released the LED will turn off.

Analysis of the Code:

In this section we will go into more depth on the source code we added to the example project. In our example project we added a loop to our Main function that included an if and an else statement.

We use a While loop with the value of 1 as the loop condition. This ensures that our code inside this loop will continue as long as we power the device.

while ( 1 )

In our project our external input is the button pushing. We want to detect this action and then drive our LED. In this example project the LED will be in the off state until the button is pressed and the LED is turned on. To accomplish this we need to test one condition, a button push. We accomplish this by using an if and an else statement.

The if statement will be used to test the button condition. As you can see our if statement will test the 0 port. For a PSoC there are eight pins on a port and the state of those pins will be a one byte HEX value. For example, the port value can be represented as a set of the individual pin values. The below table shows all 8 pin states and they give the port a value of 0000 0001 which equals 0x01 Hex. In this case there is a high value on P0(0). In our code we can test this condition to see when our button has been pressed. If the button is pressed then we will ‘see’ this action on P0(0) in the form of a 1.

















To perform the test we evaluate using a Boolean and against the value we expect for the port. If the test is true then it will give a value of 1 for the if test condition and will execute the code within the if statement.

if (PRT0DR & 0x01 )

If the button is pushed then we will execute the code within the if statement. This code will drive the Port 1 Pin 0 state to a high state and turn on the LED. In this case we will write the 0x01 value to Port 1 using the bitwise AND assign statement (&=), which will turn the first pin to a high state.

PRT1DR &= ~ 0x01

The remaining code inside the while loop is the else statement that covers all conditions not including a button press. This code executes as long as the button is not pressed. The code in the else statement will drive the Port 1 Pin 0 state to a low state and turn off the LED. In this case we will write the 0x00 value to Port 1 the bitwise inclusive OR assign statement (|=) which will turn the first pin to a low state.

PRT1DR |= 0x01 ;

Summary of the Project:

The goal of this project was to introduce the user to the CY8CKIT-001 hardware and connecting external components to the target PSoC device. Using these external connections we integrated the components into our embedded system by measuring an external input and directing that input as an output. In our example project we used a push button to drive an LED. Please see the related projects for additional example projects.

Additionally for more information on the while, if, else, and Boolean statements please see the C Language guide which is included in the root installation directory of your PSoC Designer installation. This document describes in great detail the available C language statements one can use when developing a C project in PSoC Designer.

Related Projects:

PSoC Rocks!: The user will interface an LCD with the PSoC to display a statement.
DIM LED: The user will utilize a Pulse Width Modulator (PWM) to dim an LED
ADC LCD: Use a potentiometer to display an analog voltage value on an LCD screen.