\ Just to have a twinkling shine :-)

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

$40005037 constant  PRT6_PC7 \ user LED D5
$4000500A constant  PRT1_PC2 \ user button S6
    
 
\ 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           \ 
    \ 011 3 Resistive Pull Down
    \ 100 4 Open Drain, Drives Low
    \ 101 5 Open Drain, Drives High
    \ 110 6 Strong Drive                \ 
    \ 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? ( -- ? ) PRT1_PC2 CyPins_ReadPin() 0= ;


\     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

: blinky ( -- )

  PRT1_PC2 CyPins_SetPin()    \ set output hight for button signal

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


\ Treppauf-Treppab use the component PWM_1 and its C-API
\ This fuction is disabled, see PWM_1 in TopDesign.cysch 
\ 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
  10 PWM_1_WriteCompare1()
;
