📄 pwm8_1.asm
字号:
;------------------------------------------------------------------------------
; FILENAME: PWM8_1.asm
; VERSION: Rev B, 2002 Mar 30
;------------------------------------------------------------------------------
; DESCRIPTION:
; PWM8_1 PWM8 User Module API.
;------------------------------------------------------------------------------
; Copyright (c) Cypress MicroSystems 2000-2002. All Rights Reserved.
;------------------------------------------------------------------------------
;-----------------------------------------------
; include instance specific register definitions
;-----------------------------------------------
include "m8c.inc"
include "PWM8_1.inc"
area text (ROM, REL)
;-------------------------------------------------------------------
; Declare the functions global for both assembler and C compiler.
;
; Note that there are two names for each API. First name is
; assembler reference. Name with underscore is name refence for
; C compiler. Calling function in C source code does not require
; the underscore.
;-------------------------------------------------------------------
export PWM8_1_EnableInt
export _PWM8_1_EnableInt
export PWM8_1_DisableInt
export _PWM8_1_DisableInt
export PWM8_1_Start
export _PWM8_1_Start
export PWM8_1_Stop
export _PWM8_1_Stop
export PWM8_1_WritePeriod
export _PWM8_1_WritePeriod
export PWM8_1_WritePulseWidth
export _PWM8_1_WritePulseWidth
export bPWM8_1_ReadPulseWidth
export _bPWM8_1_ReadPulseWidth
export bPWM8_1_ReadCounter
export _bPWM8_1_ReadCounter
;-----------
; EQUATES
;-----------
bfCONTROL_REG_START_BIT: equ 1 ; Control register start bit
bfINPUT_REG_CLOCK_MASK: equ 0Fh ; input register clock mask
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_EnableInt
;
; DESCRIPTION:
; Enables this PWM's interrupt by setting the interrupt enable mask bit
; associated with this User Module. Remember to call the global interrupt
; enable function by using the macro: M8C_EnableGInt.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; none.
;
; THEORY of OPERATION:
; Sets the specific user module interrupt enable mask bit.
;
;-----------------------------------------------------------------------------
PWM8_1_EnableInt:
_PWM8_1_EnableInt:
M8C_EnableIntMask PWM8_1_INT_REG, bPWM8_1_INT_MASK
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_DisableInt
;
; DESCRIPTION:
; Disables this PWM's interrupt by clearing the interrupt enable mask bit
; associated with this User Module.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; none.
;
; THEORY of OPERATION:
; Clears the specific user module interrupt enable mask bit.
;
;-----------------------------------------------------------------------------
PWM8_1_DisableInt:
_PWM8_1_DisableInt:
M8C_DisableIntMask PWM8_1_INT_REG, bPWM8_1_INT_MASK
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_Start
;
; DESCRIPTION:
; Sets the start bit in the Control register of this user module. The
; PWM will begin counting on the next input clock as soon as the
; enable input is asserted high.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; none.
;
; THEORY of OPERATION:
; Set the start bit in the Control register.
;
;-----------------------------------------------------------------------------
PWM8_1_Start:
_PWM8_1_Start:
or REG[PWM8_1_CONTROL_REG], bfCONTROL_REG_START_BIT
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_Stop
;
; DESCRIPTION:
; Disables PWM operation.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; After this function completes, the Counter register will latch any data
; written to the Period register. Writing to the Period register is
; performed using the PWM8_1_WritePeriod function.
;
; THEORY of OPERATION:
; Clear the start bit in the Control register.
;
;-----------------------------------------------------------------------------
PWM8_1_Stop:
_PWM8_1_Stop:
and REG[PWM8_1_CONTROL_REG], ~bfCONTROL_REG_START_BIT
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_WritePeriod
;
; DESCRIPTION:
; Write the period value into the Period register.
;
; ARGUMENTS:
; BYTE bPeriodValue - period count - passed in the Accumulator.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; If the PWM user module is stopped, then this value will also be
; latched into the Counter register.
;
; THEORY of OPERATION:
; Write data into the Period register.
;
;-----------------------------------------------------------------------------
PWM8_1_WritePeriod:
_PWM8_1_WritePeriod:
tst REG[PWM8_1_CONTROL_REG], bfCONTROL_REG_START_BIT
jnz .CounterRunning
; Counter is stopped. Due to chip errata, we have to set the clock low for
; the write to the period register to cause the data to be immediately transferred
; into the Counter.
.CounterStopped:
push X
mov X, A ; save the period argument
M8C_SetBank1
mov A, REG[PWM8_1_INPUT_REG] ; save the context of the clock - input register
push A
and REG[PWM8_1_INPUT_REG], F0h ; set the clock signal low
M8C_SetBank0
mov A, X
mov REG[PWM8_1_PERIOD_REG], A ; set the period register with the new period
pop A
M8C_SetBank1
mov REG[PWM8_1_INPUT_REG], A ; restore the clock
M8C_SetBank0
pop X
ret
; Counter is running - write the period into the period register.
; Upon Terminal Count this value will get loaded into the counter.
.CounterRunning:
mov REG[PWM8_1_PERIOD_REG], A
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PWM8_1_WritePulseWidth
;
; DESCRIPTION:
; Writes compare value into the PulseWidth register.
;
; ARGUMENTS:
; BYTE bPWidthValue - Pulse Width value count - passed in Accumulator.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; none.
;
; THEORY of OPERATION:
; Write data into the PulseWidth register.
;
;-----------------------------------------------------------------------------
PWM8_1_WritePulseWidth:
_PWM8_1_WritePulseWidth:
mov REG[PWM8_1_PWIDTH_REG], A
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: bPWM8_1_ReadPulseWidth
;
; DESCRIPTION:
; Reads the PulseWidth register.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; BYTE bPulseWidth - value read from PulseWidth register - returned
; in the Accumulator.
;
; SIDE EFFECTS:
; none.
;
; THEORY of OPERATION:
; Read the PulseWidth register and return value in A.
;
;-----------------------------------------------------------------------------
bPWM8_1_ReadPulseWidth:
_bPWM8_1_ReadPulseWidth:
mov A, REG[PWM8_1_PWIDTH_REG]
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: bPWM8_1_ReadCounter
;
; DESCRIPTION:
; Reads the count in the Counter register.
;
; ARGUMENTS:
; none.
;
; RETURNS:
; BYTE bCount - current count value in Count register.
;
; SIDE EFFECTS:
; Reading the Counter register may cause the Counter register to miss
; one or more counts due to the fact that the clock is stopped while
; the Counter register is read. The preferred method is to use the
; interrupt feature to determine when the counter has arrived at a
; specified value.
;
; THEORY of OPERATION:
; Reading the Counter register causes its value to be latched into the
; CompareValue register. Care must be taken to stop the clock and save
; the CompareValue register's contents before reading the counter.
;-----------------------------------------------------------------------------
bPWM8_1_ReadCounter:
_bPWM8_1_ReadCounter:
; save the input register clock setting
M8C_SetBank1
mov A, REG[PWM8_1_INPUT_REG]
push A
; disable the clock
and REG[PWM8_1_INPUT_REG], ~bfINPUT_REG_CLOCK_MASK
M8C_SetBank0
; save the PulseWidth register value
mov A, REG[PWM8_1_PWIDTH_REG]
push A
; Read the counter. This latches the counter data into
; the PulseWidth register. This may cause an interrupt.
mov A, REG[PWM8_1_COUNTER_REG]
; Read the PulseWidth register, which contains the counter value
mov A, REG[PWM8_1_PWIDTH_REG]
; Save the counter value in X
mov X, A
; Restore the PulseWidth register
pop A
mov REG[PWM8_1_PWIDTH_REG], A
; restore the input register clock setting
M8C_SetBank1
pop A
mov REG[PWM8_1_INPUT_REG], A
M8C_SetBank0
; Get the saved read counter value
mov A, X
ret
; end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -