金沙js5线路(中国)有限公司

技术热线: 4007-888-234

单键控制8个LED左闪程序

更新时间: 2019-03-26
阅读量:2077

;******************单键控制8LED左闪程序******************
;1、按键有暂停功能(定住其中1LED常亮)
;2、按键有开启功能(在暂停的状态下,开启后LED继续闪烁)
;3、按键有开机功能(在关机状态下,开机,程序从头开始)
;4、按键有关机功能(程序在运行状态还是在暂停状态,都可关机)
;************************************************       
          list p=16f877a
          include "p16f877a.inc"
;***************定义变量*************************
flag_A       equ        20h
flag_B       equ        21h
x            equ        22h
y            equ        23h
z            equ        24h
;***************主程序***************************
main      
             org       000h
             nop

 bsf       STATUS,RP0
             movlw     00h
             movwf     TRISC
             movlw     0ffh
             movwf     TRISB
             bcf       STATUS,RP0
             movlw     01h
             movwf     PORTC
             call      delay1
             bcf       flag_A,0
             bcf       flag_B,0
             bcf       STATUS,0
main_loop    btfss     PORTB,0
             call      check
             rlf       PORTC,w
             movwf     PORTC
             call      delay1
             btfss     STATUS,0
             goto      main_loop
             goto      main
;****************按键处理*************************
check
             call      delay2
check_loop1  btfsc     PORTB,0

 goto      check_loop1
check_loop2  btfss     PORTB,0
             goto      check_loop5
             call      delay2       ;延时12ms
          ;**********暂停**********
             btfss     PORTB,0                        ;\
             goto      check_loop5  ;转向关机   ; \
check_loop3  btfsc     flag_A,0                  ;  \      
             goto      check_loop7  ;转向开机   ;   \
             btfsc     flag_B,0                            ;    \
             goto      check_loop8  ;转向开启   ;    /暂停
             comf       flag_B,f                           ;   /
check_loop4  btfsc     PORTB,0                  ;  /                            
goto check_loop4 ; /
             goto      check                                ;/
          ;**********关机**********
check_loop5                         
             call      delay3        ;延时589ms     ;\

 btfsc     PORTB,0                         ; \
             goto      check_loop3                    ;  \
             call      delay4                               ;   \
             bsf       flag_A,0                            ;    \                          
             movlw     0                                    ;     \
             movwf    PORTC                           ;      \
check_loop11 btfss     PORTB,0                ;      /关机程序
             goto      check_loop11                  ;     /
check_loop6  btfsc    PORTB,0                  ;    /
             goto     check_loop6                     ;   /
             movlw    01h                                 ;  /
             movwf    PORTC                          ; /
             goto     check                              ;/ 

 ;**********开机**********
check_loop7 
             bcf      flag_A,0                          ;\
             movf     PORTC,w                     ; \ 
             movwf    PORTC                       ;   开机程序
             call     delay1                            ; /
             goto     check_loop9                 ;/
          ;**********开启**********
check_loop8 
              comf     flag_B,f                       ;\      
             movf     PORTC,w                    ; \
             movwf    PORTC                     ; /开启程序
             call     delay1                          ;/

 ;**********返回********** 
check_loop9      return   
;****************闪灯延时196ms处理程序**********************
delay1
               movlw     0FFh        
               movwf     x         
delay1_loop0   movlw     0FFh         
               movwf     y        
delay1_loop1   decfsz    y,1        
               goto      delay1_loop1          
               decfsz    x,1        
               goto      delay1_loop0
               return
;****************按键延时12ms处理程序**********************
delay2
               movlw     10h
               movwf     x
               clrf      y
delay2_loop0   decfsz    y,1
               goto      delay2_loop0
               decfsz    x,1
               goto      delay2_loop0
               return
;****************按键延时589ms处理程序**********************
delay3

movlw     0FFh        
               movwf     x
               movlw     03h        
               movwf     z
delay3_loop0   movlw     0FFh         
               movwf     y        
delay3_loop1   decfsz    y,1        
               goto      delay3_loop1          
               decfsz    x,1        
               goto      delay3_loop0
               decfsz    z,1        
               goto      delay3_loop0
               return
;****************按键延时1500ms处理程序**********************
delay4
               movlw     0FFh        
               movwf     x
               movlw     08h        
               movwf     z

delay4_loop0   movlw     0FFh         
               movwf     y        
delay4_loop1   decfsz    y,1        
               goto      delay4_loop1          
               decfsz    x,1        
               goto      delay4_loop0
               decfsz    z,1        
               goto      delay4_loop0
               return
               end



XML 地图