Blink code in C

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

cross mob
user_1665606
Level 2
Level 2
First like given

I wanted to re-create the blink example using the Cortex core only, no digital or analog modules. So far this is what I got but I still can't see the LED (port 2 pin2) blinking. What am I missing?

   

 

   

#include <project.h>
#include <cypins.h>
#include <cydevice_trm.h>

   

#define CYREG_PRT2_PC1 0x40005011u         //define pin 2.2
#define CyPins_SetPin(pinPC)     ( *(reg8 *)(pinPC) |= CY_PINS_PC_DATAOUT)     //set pin
#define CyPins_ClearPin(pinPC)   ( *(reg8 *)(pinPC) &= ((uint8)(~CY_PINS_PC_DATAOUT)))    //clear pin

   


int main()
{
  
    while(0)
    {
        CyPins_SetPin(CYREG_PRT2_PC1);
        CyDelay(1000);
        CyPins_ClearPin(CYREG_PRT2_PC1);
        CyDelay(1000);        
    }
    return(1);
}

0 Likes
2 Replies
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

This Appnote can help you http://www.cypress.com/documentation/application-notes/an72382-using-psoc-3-and-psoc-5lp-gpio-pins

   

check page 10, section Toggle GPIOs Faster with Data Registers.

   


Hope it helps

   

Carlos

0 Likes

Page 7 🙂 Thank you Carlos, it worked! So in case anyone else wants to build a blink example, here it goes:

   

 

   

for(;;) {

   

/* Set MyPin output state to HIGH */
MyPin_Write(1);
/* Delay for 500 ms */
CyDelay(500);
/* Set MyPin output state to LOW */
MyPin_Write(0);
/* Delay for 500 ms */
CyDelay(500); }

   

 

   

Keep in mind you need to drop a pin in the schematics section first, name it (such as 'MyPin'), set it to digital out, no HW connection, strong drive. That's it! The PSOC5 API seems very useful!

0 Likes