how do i toggle a software controlled digital outpin using setpin and clearpin APIs'?
kindly see the project attached below
You can toggle using CyPins_SetPin(CYREG_PRTx_PCy) and CyPins_ClearPin(CYREG_PRTx_PCy) where x and y are port and pin configs which in the attached project is PRT1_PC7. (x=1,y=7)
Declare a couple of macros
#define LED2on LED_2_Write(1)
#define LED2off LED_2_Write(0)
Then use in code –
Note, when your project compiled you have some warnings, like on this –
if (statusflag= TRUE)
if (statusflag == TRUE)
Always clear your warning issues.
thnx srim, thnx dana..it worked!!!
neha i'll suggest u
dont depend on API use basic software coding constructs
use delays P=0 and then gave delay again put these statements in loop to get toggling digital led or output
I am sorry, but I have to contradict your last post.
Not using APIs is a technique that will lead into a one-way-road dead-end-street.
The world is changing and so are PSoCs (there is some rumor about a PSoC4 coming). One thing that can be kept unchanged is the API for an underlying technical (hardware) function. So using APIs will prevent you from having to change your program when the outer world suddenly looks different. That might be a simple thing like a pin swapped by accident on your PCB. Everything went well on the Kit, now on frabicated pcb it won't. So change the pin. In creator when you did a good work it is only in the pins-window assigning a new value (or two if it was a swap). No API? Going trugh the program and looking up all occurences of this port- and pin-accesses and do not forget a single one. Now can you imagine what amount of program-changes you might have, when you switch from a PSoC3 to a PSoC5 when you hand-coded everything and didn't use APIs? I even find it easier to use an API for an LED-component than to use some construct to change a port pin without influencing the other pins on the same port.
You will sleep better when using APIs.
I can only second Bob with regards to the API. Use them, they make your life easier. You don't need to read so much documentation, and they avoid many pitfalls and traps for you.
However, there are two exception: if you need to access features which aren't exposed via the APIs, or if you really really need to care about performance, and the APIs provide too much overhead (which is rarely the case with PSoC, since the generated code is already streamlined for your configuration). And for the latter one, look up the two rules of Donald Knuth about performance optimizations, before you do any :)
I will contradict the API rule as follows -
1) The reason we love PSOC is its register based architecture. Finally analog meets digital
meets FPGA flexibility.
2) Coders writing APIs do not have your specific project in mind and its performance needs.
3) We love PSOC because there are APIs for the basics (contradicting my own points).
4) All of us are getting pushed competitively, exploiting HW and SW is how that gets done.
5) There are dangers in register manipulation, same is true trying to get an ice cream cone
at MacDonalds. :)
6) PSOC has a component authoring tool for the purpose of creating off the wall components.
7) PSOC has Verilog to get down to the sub register level, gates. Hoorah.
So lets walk that tightrope and memorialize the ones that fall, and laud the ones that make it :)
Thnx sachin, Bob, hli and danaa.
In PSoC 1 I created a h file for all the I/O ports. This let me toggle all pins. EX: P1 . Turm on port 1 bit 1. Can I use this type of code for the PSoC 3?