Accessing pins as array

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello everyone,

First of all this my first time playing with PSoC creator or with any Cypress PSoC device. And i am really amazed: it's incredible.

Since I have some free time these days I decided to learn about the way that this uC are programmed. So...

I am blinking some leds. I saw that it's possible to access pins as a port which is quite nice. But is it possible to access them from an array?

Below my code. Thank you in advance.

/* ========================================

*

* Copyright YOUR COMPANY, THE YEAR

* All Rights Reserved

* UNPUBLISHED, LICENSED SOFTWARE.

*

* CONFIDENTIAL AND PROPRIETARY INFORMATION

* WHICH IS THE PROPERTY OF your company.

*

* ========================================

*/

#include "project.h"

#include "cypins.h"

int array[4]={LED_1_0,LED_1_1,LED_1_2,LED_1_3};

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

        for(int i=1;i<16;i++){

            LED_1_Write(i);

            CyDelay(1000);

        }

        for(int i=1;i<4;i++){

            CyPins_SetPin(??);

            CyDelay(1000);

        }       

        /* Place your application code here. */

    }

}

/* [] END OF FILE */

0 Likes
1 Solution
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Not directly. You can use an array to store function pointers to the respective Pin_Set() functions. See https://www.cprogramming.com/tutorial/function-pointers.html

On a PSoC5 you could use the ARM BitBanding functionality (which allows to set/reset single bits by writing into a specific memory location), but then the pins should all belong to the same port.

View solution in original post

4 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Not directly. You can use an array to store function pointers to the respective Pin_Set() functions. See https://www.cprogramming.com/tutorial/function-pointers.html

On a PSoC5 you could use the ARM BitBanding functionality (which allows to set/reset single bits by writing into a specific memory location), but then the pins should all belong to the same port.

Anonymous
Not applicable

I have been trying to work with function pointers with the PSoC 5. So far I haven't got them to work. Can you guys give me an example of how you did it? This is what I have that complies. But it still doesn't work.  I have tried other things metioned in this document http://www.cypress.com/file/59071/download without any luck.

//definition

typedef void const *(Write_pin_on(void));

Write_pin_on *pins[4]= {

      &pin_1_on,

      &pin_2_on,

      &pin_3_on,

      &pin_4_on,

};

//function call

(*(pins[0]));

0 Likes

Syntax is a bit different, see here...

Bob

0 Likes
Anonymous
Not applicable

yeah, I just figured it out. I was going to replay and say I messed up on the parentheses on how to do it. But I got it. Thanks for the reply

0 Likes