⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm16_2.lis

📁 Application Note Abstract This Application Note introduces a complete and detailed PSoC&reg project
💻 LIS
📖 第 1 页 / 共 4 页
字号:
 001A           
 001A           
 001A           ;-----------------------------------------------------------------------------
 001A           ;  FUNCTION NAME: PWM16_2_WritePeriod
 001A           ;
 001A           ;  DESCRIPTION:
 001A           ;     Write the period value into the Period register.
 001A           ;
 001A           ;  ARGUMENTS:
 001A           ;     WORD  wPeriodValue - period count - 
 001A           ;              MSB passed in X register
 001A           ;              LSB passed in A register
 001A           ;
 001A           ;  RETURNS:
 001A           ;     none.
 001A           ;
 001A           ;  SIDE EFFECTS:
 001A           ;     If the PWM user module is stopped, then this value will also be
 001A           ;     latched into the Counter registers.
 001A           ;
 001A           ;  THEORY of OPERATION:  
 001A           ;     Write data into the Period registers.
 001A           ;
 001A           ;-----------------------------------------------------------------------------
 001A            PWM16_2_WritePeriod:
 001A           _PWM16_2_WritePeriod:
 001A 492B01       tst   REG[PWM16_2_CONTROL_LSB_REG], bfCONTROL_REG_START_BIT
 001D B027         jnz   .CounterRunning
 001F           
 001F           ; Counter is stopped.  Due to chip errata, we have to set the clock low for
 001F           ; the write to the period register to cause the data to be immediately transferred
 001F           ; into the Counter.
 001F           .CounterStopped:
 001F 10           push  X
 0020 5C           mov   X, A                                   ; save the period argument
 0021 7110          or    F, FlagXIOMask
 0023 5D29         mov   A, REG[PWM16_2_INPUT_LSB_REG]         ; save the context of the clock - input register
 0025 08           push  A
 0026 4129F0       and   REG[PWM16_2_INPUT_LSB_REG], F0h       ; set the clock signal low
 0029 412DF0       and   REG[PWM16_2_INPUT_MSB_REG], F0h
 002C 70EF          and   F, ~FlagXIOMask
 002E 5B           mov   A, X                                      
 002F 6029         mov   REG[PWM16_2_PERIOD_LSB_REG], A            ; set the period register with the new period
 0031 18           pop   A
 0032 20           pop   X
 0033 08           push  A
 0034 5B           mov   A, X
 0035 602D         mov   REG[PWM16_2_PERIOD_MSB_REG], A               
 0037 18           pop   A
 0038 7110          or    F, FlagXIOMask
 003A 6029         mov   REG[PWM16_2_INPUT_LSB_REG], A         ; restore the clock
 003C 210F         and   A, 0Fh                                 ; High nibble is always 0x3 for higher order bits 
 003E 2930         or    A, 30h
 0040 602D         mov   REG[PWM16_2_INPUT_MSB_REG], A 
 0042           
 0042 70EF          and   F, ~FlagXIOMask
 0044 7F           ret
 0045           
 0045           ; Counter is running - write the period into the period register.
 0045           ; Upon Terminal Count this value will get loaded into the counter.
 0045           .CounterRunning:
 0045 6029         mov   REG[PWM16_2_PERIOD_LSB_REG], A
 0047 5B           mov   A, X
 0048 602D         mov   REG[PWM16_2_PERIOD_MSB_REG], A
 004A 7F           ret
 004B           
 004B           
 004B           ;-----------------------------------------------------------------------------
 004B           ;  FUNCTION NAME: PWM16_2_WritePulseWidth
 004B           ;
 004B           ;  DESCRIPTION:
 004B           ;     Writes compare value into the PulseWidth register.
 004B           ;
 004B           ;  ARGUMENTS:
 004B           ;     WORD  wPulseWidth - compare value count - 
 004B           ;              MSB passed in X register
 004B           ;              LSB passed in A register
 004B           ;
 004B           ;  RETURNS:
 004B           ;     none.
 004B           ;
 004B           ;  SIDE EFFECTS:
 004B           ;     none.
 004B           ;
 004B           ;  THEORY of OPERATION:  
 004B           ;     Write data into the PulseWidth registers.
 004B           ;
 004B           ;-----------------------------------------------------------------------------
 004B            PWM16_2_WritePulseWidth:
 004B           _PWM16_2_WritePulseWidth:
 004B 602A         mov   REG[PWM16_2_PWDITH_LSB_REG], A 
 004D 5B           mov   A, X
 004E 602E         mov   REG[PWM16_2_PWDITH_MSG_REG], A
 0050 7F           ret
 0051           
 0051           
 0051           ;-----------------------------------------------------------------------------
 0051           ;  FUNCTION NAME: wPWM16_2_ReadPulseWidth
 0051           ;
 0051           ;  DESCRIPTION:
 0051           ;     Reads the PulseWidth registers.
 0051           ;
 0051           ;  ARGUMENTS:
 0051           ;     none.
 0051           ;
 0051           ;  RETURNS:
 0051           ;     WORD  wPulseWidth - value read from PulseWidth register - 
 0051           ;           LSB returned in A register
 0051           ;           MSB returned in X register           
 0051           ;
 0051           ;  SIDE EFFECTS:
 0051           ;     none.
 0051           ;
 0051           ;  THEORY of OPERATION:  
 0051           ;     Read the PulseWidth register and return value in A.
 0051           ;
 0051           ;-----------------------------------------------------------------------------
 0051            wPWM16_2_ReadPulseWidth:
 0051           _wPWM16_2_ReadPulseWidth:
 0051 5D2E         mov   A, REG[PWM16_2_PWDITH_MSG_REG]
 0053 5C           mov   X, A
 0054 5D2A         mov   A, REG[PWM16_2_PWDITH_LSB_REG]
 0056 7F           ret
 0057           
 0057           
 0057           ;-----------------------------------------------------------------------------
 0057           ;  FUNCTION NAME: wPWM16_2_ReadCounter
 0057           ;
 0057           ;  DESCRIPTION:
 0057           ;     Reads the count in the Counter register.
 0057           ;
 0057           ;  ARGUMENTS:
 0057           ;     none.
 0057           ;
 0057           ;  RETURNS:
 0057           ;     WORD  wCount - current count value in Count register.
 0057           ;        LSB - returned in A register
 0057           ;        MSB - returned in X register
 0057           ;
 0057           ;  SIDE EFFECTS:
 0057           ;     Reading the Counter register may cause the Counter register to miss
 0057           ;     one or more counts due to the fact that the clock is stopped while
 0057           ;     the Counter register is read.  The preferred method is to use the 
 0057           ;     interrupt feature to determine when the counter has arrived at a 
 0057           ;     specified value.
 0057           ;
 0057           ;  THEORY of OPERATION:  
 0057           ;     Reading the Counter register causes its value to be latched into the 
 0057           ;     CompareValue register.  Care must be taken to stop the clock and save 
 0057           ;     the CompareValue register's contents before reading the counter.
 0057           ;
 0057           ;-----------------------------------------------------------------------------
 0057            wPWM16_2_ReadCounter:
 0057           _wPWM16_2_ReadCounter:
 0057             
 0000              bOrigClockSetting:      EQU   0
 0001              bOrigCompareValue:      EQU   1
 0002              wCounter:               EQU   2     ; must be at top of stack frame
 0004              STACK_FRAME_SIZE:       EQU   4     ; stack frame is 4 bytes
 0057           
 0057              ; create a stack frame
 0057 4F           mov   X, SP
 0058 3804         add   SP, STACK_FRAME_SIZE
 005A           
 005A              ; save the input register clock setting
 005A 7110          or    F, FlagXIOMask
 005C 5D29         mov   A, REG[PWM16_2_INPUT_LSB_REG]
 005E 5400         mov   [X+bOrigClockSetting], A
 0060              ; disable the clock
 0060 622900       mov   REG[PWM16_2_INPUT_LSB_REG], bfINPUT_REG_NULL
 0063 622D30       mov   REG[PWM16_2_INPUT_MSB_REG], bfINPUT_REG_PREV_MASK
 0066 70EF          and   F, ~FlagXIOMask
 0068           
 0068              ;--------------------------
 0068              ;  Process the MSB byte 
 0068              ;--------------------------
 0068              ; save the PulseWidth register value
 0068 5D2E         mov   A, REG[PWM16_2_PWDITH_MSG_REG]    
 006A 5401         mov   [X+bOrigCompareValue], A
 006C              ; Read the counter. This latches the counter data into
 006C              ; the PulseWidth register.  This may cause an interrupt.
 006C 5D2C         mov   A, REG[PWM16_2_COUNTER_MSB_REG]    
 006E              ; Read the PulseWidth register, which contains the counter value
 006E 5D2E         mov   A, REG[PWM16_2_PWDITH_MSG_REG]    
 0070 5402         mov   [X+wCounter], A
 0072           
 0072              ; Restore the PulseWidth register
 0072 5201         mov   A, [X+bOrigCompareValue]
 0074 602E         mov   REG[PWM16_2_PWDITH_MSG_REG], A
 0076           
 0076              ;--------------------------
 0076              ;  Process the LSB byte 
 0076              ;--------------------------
 0076              ; save the PulseWidth register value
 0076 5D2A         mov   A, REG[PWM16_2_PWDITH_LSB_REG]    
 0078 5401         mov   [X+bOrigCompareValue], A
 007A              ; Read the counter. This latches the counter data into
 007A              ; the PulseWidth register.  This may cause an interrupt.
 007A 5D28         mov   A, REG[PWM16_2_COUNTER_LSB_REG]    
 007C              ; Read the PulseWidth register, which contains the counter value
 007C 5D2A         mov   A, REG[PWM16_2_PWDITH_LSB_REG]    
 007E 5403         mov   [X+wCounter+1], A
 0080           
 0080              ; Restore the PulseWidth register
 0080 5201         mov   A, [X+bOrigCompareValue]
 0082 602A         mov   REG[PWM16_2_PWDITH_LSB_REG], A
 0084           
 0084              ; restore the input register clock setting
 0084 7110          or    F, FlagXIOMask
 0086 5200         mov   A, [X+bOrigClockSetting]
 0088 210F         and   A, bfINPUT_REG_CLOCK_MASK
 008A 2930         or    A, bfINPUT_REG_PREV_MASK
 008C 602D         mov   REG[PWM16_2_INPUT_MSB_REG], A
 008E 5200         mov   A, [X+bOrigClockSetting]
 0090 6029         mov   REG[PWM16_2_INPUT_LSB_REG], A
 0092 70EF          and   F, ~FlagXIOMask
 0094           
 0094              ; Setup the return value in X and A
 0094 5202         mov   A, [X+wCounter]   ; get the MSB 
 0096 08           push  A
 0097 5203         mov   A, [X+wCounter+1] ; LSB in A
 0099 20           pop   X
 009A           
 009A              ; Delete the stack frame
 009A 38FC         ADD   SP, -(STACK_FRAME_SIZE)
 009C           
 009C 7F           ret
 009D           
 009D           ; end of PWM16 API code
 009D           
 009D           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -