;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME:   PROVOZNI_LED.asm
;;  Version: 1.40, Updated on 2012/3/2 at 9:14:50
;;  Generated by PSoC Designer 5.2.2551
;;
;;  DESCRIPTION: LED user module.
;;
;;
;;  NOTE: User Module APIs conform to the fastcall16 convention for marshalling
;;        arguments and observe the associated "Registers are volatile" policy.
;;        This means it is the caller's responsibility to preserve any values
;;        in the X and A registers that are still needed after the API functions
;;        returns. For Large Memory Model devices it is also the caller's 
;;        responsibility to perserve any value in the CUR_PP, IDX_PP, MVR_PP and 
;;        MVW_PP registers. Even though some of these registers may not be modified
;;        now, there is no guarantee that will remain the case in future releases.
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress Semiconductor 2012. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************

include "PROVOZNI_LED.inc"
include "memory.inc"

export _PROVOZNI_LED_Start
export  PROVOZNI_LED_Start

export _PROVOZNI_LED_Stop
export  PROVOZNI_LED_Stop

export _PROVOZNI_LED_On
export  PROVOZNI_LED_On

export _PROVOZNI_LED_Off
export  PROVOZNI_LED_Off

export _PROVOZNI_LED_Switch
export  PROVOZNI_LED_Switch

export _PROVOZNI_LED_Invert
export  PROVOZNI_LED_Invert

export _PROVOZNI_LED_GetState
export  PROVOZNI_LED_GetState


AREA UserModules (ROM, REL)


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PROVOZNI_LED_Start(void)
;  FUNCTION NAME: PROVOZNI_LED_Stop(void)
;
;  FUNCTION NAME: PROVOZNI_LED_Switch(void)
;
;  DESCRIPTION: ( Switch )
;     Turn LED on or off     
;
;  DESCRIPTION: ( Start, Stop )
;     Turn LED off                       
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:  ( Switch )
;     A => If 0, turn off LED, if > 0 turn on LED
;
;  ARGUMENTS:  ( Start, Stop )
;      None
;
;  RETURNS:  none
;
;  SIDE EFFECTS:
;    REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
_PROVOZNI_LED_On:
 PROVOZNI_LED_On:
   mov  A,0x01
   jmp  PROVOZNI_LED_Switch 

_PROVOZNI_LED_Start:
 PROVOZNI_LED_Start:
_PROVOZNI_LED_Stop:
 PROVOZNI_LED_Stop:
_PROVOZNI_LED_Off:
 PROVOZNI_LED_Off:
   mov  A,0x00

_PROVOZNI_LED_Switch:
 PROVOZNI_LED_Switch:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_PROLOGUE RAM_USE_CLASS_2
   RAM_SETPAGE_CUR >Port_1_Data_SHADE

   or   A,0x00                                   ; Check mode
   jz   .Turn_Off_LED

.Turn_On_LED:
IF(0)                                            ; Active High Digit Drive
   or   [Port_1_Data_SHADE],PROVOZNI_LED_PinMask
ELSE                                             ; Active Low Digit Drive
   and  [Port_1_Data_SHADE],~PROVOZNI_LED_PinMask
ENDIF
   jmp  .Switch_LED

.Turn_Off_LED:
IF(0)                      ; Active High Digit Drive
   and  [Port_1_Data_SHADE],~PROVOZNI_LED_PinMask
ELSE                              ; Active Low Digit Drive
   or   [Port_1_Data_SHADE],PROVOZNI_LED_PinMask
ENDIF

.Switch_LED:
   mov  A,[Port_1_Data_SHADE]
   mov  reg[PROVOZNI_LED_PortDR],A

   RAM_EPILOGUE RAM_USE_CLASS_2
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION



.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PROVOZNI_LED_Invert(void)
;
;  DESCRIPTION:
;     Invert state of LED                               
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: none
;
;  RETURNS:  none
;
;  SIDE EFFECTS:
;    REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
_PROVOZNI_LED_Invert:
 PROVOZNI_LED_Invert:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_PROLOGUE RAM_USE_CLASS_2
   RAM_SETPAGE_CUR >Port_1_Data_SHADE

   xor  [Port_1_Data_SHADE],PROVOZNI_LED_PinMask
   mov  A,[Port_1_Data_SHADE]
   mov  reg[PROVOZNI_LED_PortDR],A

   RAM_EPILOGUE RAM_USE_CLASS_2
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PROVOZNI_LED_GetState(void)
;
;  DESCRIPTION:
;     Get state of LED
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: none
;
;  RETURNS:  
;    State of LED   1 = ON,  0 = OFF
;
;  SIDE EFFECTS:
;    REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
_PROVOZNI_LED_GetState:
 PROVOZNI_LED_GetState:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_PROLOGUE RAM_USE_CLASS_2
   RAM_SETPAGE_CUR >Port_1_Data_SHADE

   mov   A,[Port_1_Data_SHADE]         ; Get shade value
IF(0)                                  ; Active High Digit Drive
   // Nothing for now
ELSE                                   ; Active Low Digit Drive
   cpl   A                             ; Invert bit if Active low
ENDIF
   and   A,PROVOZNI_LED_PinMask        ; Mask off the trash
   jz    .End_LED_GS                   ; If zero, we're done
   mov   A,0x01                        ; Return a 1 no mater what the mask is.

.End_LED_GS:
   RAM_EPILOGUE RAM_USE_CLASS_2
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION
