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

📄 led_ctrl.psm

📁 基于spartan3e的串口调试和检测程序,可直接烧写,检测结果将同时通过LCD显示出来
💻 PSM
📖 第 1 页 / 共 3 页
字号:
                      ; KCPSM3 Program - LED control with Pulse Width Modulation (PWM).
                      ;
                      ; Design provided for use with the design 'low_cost_design_authentication_for_spartan_3e.vhd'
                      ; and the Spartan-3E Starter Kit. This design provides the token 'real' application to be
                      ; protected by design authentication.
                      ;
                      ; Ken Chapman - Xilinx Ltd
                      ;
                      ; Version v1.00 - 9th November 2006
                      ;
                      ; This code automatically sequences the LEDs on the board using PWM to change intensity.
                      ; It also checks for correct design authentication and will perform a different sequence if
                      ; the design is not authorised.
                      ;
                      ;
                      ;**************************************************************************************
                      ; NOTICE:
                      ;
                      ; Copyright Xilinx, Inc. 2006.   This code may be contain portions patented by other
                      ; third parties.  By providing this core as one possible implementation of a standard,
                      ; Xilinx is making no representation that the provided implementation of this standard
                      ; is free from any claims of infringement by any third party.  Xilinx expressly
                      ; disclaims any warranty with respect to the adequacy of the implementation, including
                      ; but not limited to any warranty or representation that the implementation is free
                      ; from claims of any third party.  Furthermore, Xilinx is providing this core as a
                      ; courtesy to you and suggests that you contact all third parties to obtain the
                      ; necessary rights to use this implementation.
                      ;
                      ;
                      ;**************************************************************************************
                      ; Port definitions
                      ;**************************************************************************************
                      ;
                      ;
                      ;
                      CONSTANT LED_port, 80               ;8 simple LEDs
                      CONSTANT LED0, 01                   ;       LD0 - bit0
                      CONSTANT LED1, 02                   ;       LD1 - bit1
                      CONSTANT LED2, 04                   ;       LD2 - bit2
                      CONSTANT LED3, 08                   ;       LD3 - bit3
                      CONSTANT LED4, 10                   ;       LD4 - bit4
                      CONSTANT LED5, 20                   ;       LD5 - bit5
                      CONSTANT LED6, 40                   ;       LD6 - bit6
                      CONSTANT LED7, 80                   ;       LD7 - bit7
                      ;
                      CONSTANT LED_read_port, 00          ;read back of current LED drive values
                      ;
                      ;
                      CONSTANT security_request_port, 40  ;Port to stimulate security KCPSM3 processor
                      CONSTANT security_interrupt, 01     ; interrupt - bit0
                      ;
                      ;
                      ;A FIFO buffer links the security KCPSM3 processor to the application KCPSM3 processor.
                      ;  This application processor controls and reads the FIFO.
                      ;  The security processor writes to the FIFO.
                      ;
                      CONSTANT link_fifo_control_port, 20 ;FIFO control
                      CONSTANT link_fifo_reset, 01        ;     reset - bit0
                      ;
                      CONSTANT link_FIFO_status_port, 01  ;FIFO status input
                      CONSTANT link_FIFO_data_present, 01 ;      half full - bit0
                      CONSTANT link_FIFO_half_full, 02    ;           full - bit1
                      CONSTANT link_FIFO_full, 04         ;   data present - bit2
                      ;
                      CONSTANT link_FIFO_read_port, 02    ;read FIFO data
                      ;
                      ;
                      ;
                      ;**************************************************************************************
                      ; Special Register usage
                      ;**************************************************************************************
                      ;
                      ;
                      ;
                      ;
                      ;**************************************************************************************
                      ;Scratch Pad Memory Locations
                      ;**************************************************************************************
                      ;
                      CONSTANT PWM_duty_counter, 00       ;Duty Counter 0 to 255 within 1KHz period (1ms)
                      CONSTANT PWM_channel0, 01           ;PWM settings for each channel
                      CONSTANT PWM_channel1, 02           ; Channels 0 to 7 = LEDs 0 to 7
                      CONSTANT PWM_channel2, 03
                      CONSTANT PWM_channel3, 04
                      CONSTANT PWM_channel4, 05
                      CONSTANT PWM_channel5, 06
                      CONSTANT PWM_channel6, 07
                      CONSTANT PWM_channel7, 08
                      CONSTANT ISR_preserve_s0, 0D        ;preserve register contents during Interrupt Service Routine
                      CONSTANT ISR_preserve_s1, 0E
                      CONSTANT ISR_preserve_s2, 0F
                      ;
                      ;
                      CONSTANT LED0_sequence, 10          ;LED sequence values
                      CONSTANT LED1_sequence, 11
                      CONSTANT LED2_sequence, 12
                      CONSTANT LED3_sequence, 13
                      CONSTANT LED4_sequence, 14
                      CONSTANT LED5_sequence, 15
                      CONSTANT LED6_sequence, 16
                      CONSTANT LED7_sequence, 17
                      ;
                      ;
                      ;
                      ;**************************************************************************************
                      ;Useful data constants
                      ;**************************************************************************************
                      ;
                      ;
                      ;
                      ;
                      ;
                      ;
                      ;
                      ;**************************************************************************************
                      ;Initialise the system
                      ;**************************************************************************************
                      ;
                      ; All PWM channels initialise to off (zero).
                      ; Simple I/O outputs will remain off at all times.
                      ;
          cold_start: LOAD s0, 00
                      LOAD s1, PWM_channel0
          clear_loop: STORE s0, (s1)
                      COMPARE s1, PWM_channel7
                      JUMP Z, enable_int
                      ADD s1, 01
                      JUMP clear_loop
                      ;
          enable_int: ENABLE INTERRUPT                    ;interrupts used to set PWM frequency
                      ;
                      ;
                      ; Initialise LED pattern sequence
                      ;
                      LOAD s0, 01                         ;trigger to start wave pattern
                      STORE s0, LED0_sequence
                      LOAD s0, 00
                      STORE s0, LED1_sequence
                      STORE s0, LED2_sequence
                      STORE s0, LED3_sequence
                      STORE s0, LED4_sequence
                      STORE s0, LED5_sequence
                      STORE s0, LED6_sequence
                      STORE s0, LED7_sequence
                      ;
                      ;
                      ; Reset authentication check counter
                      ;
                      LOAD sF, 00
                      ;
                      ;
                      ;**************************************************************************************
                      ; Main program
                      ;**************************************************************************************
                      ;
                      ; Provides a pattern of interest on the LEDs :-)
                      ;
                      ; Each LED increases intensity in 8 steps and then decreases intensity in 8 steps until it is off.
                      ; The middle LEDs (LD2 to LD5) each start to turn on when either neighbour is turned half on and increasing
                      ; to provide the effect of a passing a 'wave' of light passing from side to side. The pair of LEDs at each
                      ; (LD0, Ld1 and LD6, LD7) are required to reflect the 'wave' so that the pattern continues.
                      ;
                      ; I'm sure this code cold be written in more elegant way, but I leave that as an exercise to you :-)
                      ;
                      ;
                      ; Using a simple software counter (implemented by register sF) the design occasionally requests an
                      ; authorisation message from the authentication processor. If it receives a PASS message it continues
                      ; normally but if it receives a FAIL message the LED pattern is changed.
                      ;
                      ;
                      ;
          warm_start: ADD sF, 01                          ;authentication check timer
                      JUMP C, authentication_check        ;Check made approximately every 8 seconds.
                      ;
 normal_LED_sequence: LOAD s2, 03                         ;simple delay loop (delay will be increased by ISR processing)
       delay_s2_loop: LOAD s1, FF
       delay_s1_loop: LOAD s0, FF
       delay_s0_loop: SUB s0, 01
                      JUMP NC, delay_s0_loop
                      SUB s1, 01
                      JUMP NC, delay_s1_loop
                      SUB s2, 01
                      JUMP NC, delay_s2_loop
                      ;
                      ;Pattern generation
                      ;
                      FETCH s0, LED0_sequence             ;read sequence for LED0
                      COMPARE s0, 00
                      JUMP Z, test_LED0_start
                      SUB s0, 20                          ;Count longer to ensure end stops then reset count if maximum
                      JUMP Z, update_LED0

⌨️ 快捷键说明

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