cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

DaHu_285096
Contributor II

Hi,

I have 8 digital outputs that are on various pins of the 5LP that I want to control as a port using an 8-bit variable in code.

I created a digital output pin then then set number of pins to 8. I named the port "POWER"

Next I selected "Display as Bus" mapping.

Then I went to "pins" tab and set the pin designation.

I am having trouble setting the value of "PORT" in code.

The intellisense in PSOC creator shows "POWER_0, POWER_1 etc but I cannot work out correct syntax to do equivalent of POWER_Write(23) for instance.

Have I set this up wrong or simply not using corect syntax?

Thanks

0 Likes
1 Solution
BiBi_1928986
Contributor II

Hello DaHu.

The example by Moto is perfect when you have an entire 8-bit port available.

When you have random GPIO's from several ports, you can use the Control_Reg component.  Now you can connect just about any GPIO output pin to the Control Reg output signal.

To write to this component is very simple.

Control_Reg_1_Write(i);    /* where i is uint8 */

pastedImage_0.png

This is not a bidirectional solution.  It is for writing only to the GPIO's.

Good luck with your project.

View solution in original post

3 Replies
MotooTanaka
Esteemed Contributor

Hi,

That is an interesting question!

Although I knew that we can have a pin displayed as a bus,

I have never tried write/read as a bus.

So I used my CY8CKIT-059 and used P3[7:0] as an 8-bit bus.

schematic

002-schematic.JPG

POWER pin configuration

004-POWER_Pins.JPG

005-POWER_Mapping.JPG

Pins

003-Pins.JPG

main.c

====================

#include "project.h"

#include "stdio.h"

#define STR_BUF_LEN 64

char str[STR_BUF_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

int main(void)

{

    int i, data ;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    for(;;)

    {

        for (i = 0 ; i < 0x100 ; i++ ) {

            POWER_Write(i) ;

            CyDelay(500) ;

            data = POWER_Read() ;

            snprintf(str, STR_BUF_LEN, "%d\n\r", data) ;

            print(str) ;

            CyDelay(500) ;

        }

    }

}

====================

Tera Term log

001-TeraTerm-log.JPG

So as far as setting pins in a port as a bus, it seems to be working.

moto

BiBi_1928986
Contributor II

Hello DaHu.

The example by Moto is perfect when you have an entire 8-bit port available.

When you have random GPIO's from several ports, you can use the Control_Reg component.  Now you can connect just about any GPIO output pin to the Control Reg output signal.

To write to this component is very simple.

Control_Reg_1_Write(i);    /* where i is uint8 */

pastedImage_0.png

This is not a bidirectional solution.  It is for writing only to the GPIO's.

Good luck with your project.

View solution in original post

DaHu_285096
Contributor II

Thanks, that solves the issues nicely

0 Likes