\ Just to have a twinkling shine :-)

: ms ( u -- ) 0 ?do 4000 0 do loop loop ; \ Calibrated for 80 MHz..


$40005030 constant  PRT6_PC0 
$40005031 constant  PRT6_PC1 \ switch SW2
$40005032 constant  PRT6_PC2 
$40005033 constant  PRT6_PC3 \ red LED4
$40005034 constant  PRT6_PC4 
$40005035 constant  PRT6_PC5 
$40005037 constant  PRT6_PC7 
      
 
\ Port wide configuration register PRTx_PCy: 
\ Bit [0..7] 
\ 0 data out
\ 1 driveMode 0
\ 2 driveMode 1
\ 3 driveMode 2
\ bit 321
    \ 000 0 High-Impedance Analog
    \ 001 1 High-impedance Digital
    \ 010 2 Resistive Pull Up           \ PRT6_PC1 init. in main.c
    \ 011 3 Resistive Pull Down
    \ 100 4 Open Drain, Drives Low
    \ 101 5 Open Drain, Drives High
    \ 110 6 Strong Drive                \ PRT6_PC3 init. in main.c
    \ 111 7 Resistive Pull Up and Down
\ 4 data in (pin state)
\ 5 bidirEN
\ 6 slew
\ 7 bypass  
  
\ for more infos see PSoC 5LP Register TRM:
\ http://www.cypress.com/documentation/technical-reference-manuals/psoc-5lp-registers-trm-technical-reference-manual
\ 1.3.238    PRT[0..11]_PRT


: button? ( -- ? ) 1 4 lshift PRT6_PC1 cbit@ 0= ;


\ I. Blinky solution with direct portmanipulation: 

: blinky1 ( -- )
  
  1 PRT6_PC1 cbis!  \ set output hight for button signal
  
  begin
    1 PRT6_PC3 cbis!
    button? if 1500 ms else 200 ms then
    1 PRT6_PC3 cbic!
    200 ms    
  key? until
;


\ II. Blinky solution via HardwareAbstractionLayer:
\     In this way you can use all PSoC-Components without any restrictions 
\     See HAL.s and main.c; based on API from PSoC-Creator

: blinky2 ( -- )

  PRT6_PC1 CyPins_SetPin()    \ set output hight for button signal

  begin
    LEDon()  
    button? if 1500 ms else 200 ms then
    LEDoff()   
    200 ms
  key? until
;


\ Treppauf-Treppab use the component PWM_1 and its C-API
\ See HAL.s and main.c
\ To use all features of the chip install PSoC-Creator:
\ http://www.cypress.com/products/psoc-creator-integrated-design-environment-ide

: Treppauf-Treppab ( -- )

  begin
    255 0 do I PWM_1_WriteCompare1() 5 ms loop
    0 255 do I PWM_1_WriteCompare1() 5 ms -1 +loop
  key? until
;
