daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Apr 17th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     list p=16f627
  2.     include "p16f627.inc"
  3.     errorlevel -302
  4.    
  5.     __CONFIG 0x3D18
  6.    
  7.     movlw 0x07
  8.     movwf CMCON
  9.    
  10.     banksel TRISA
  11.    
  12.     movlw 0xFF
  13.     movwf TRISA
  14.     clrf TRISB
  15.    
  16.     banksel PORTA
  17.  
  18. t1  equ 0x20
  19. t2  equ 0x21
  20. t3  equ 0x22
  21. tn  equ 0x23
  22.  
  23. main:
  24.     clrf    PORTB
  25.    
  26. loop:
  27.     bsf PORTB, 0        ; Set green light
  28.    
  29.     btfss   PORTA, 0        ; Check if switch is pressed
  30.     goto    loop            ; Switch isn't pressed so stay green
  31.    
  32.     movlw   3           ;
  33.     movwf   tn          ; Delay 3 seconds
  34.     call    delay_n         ;
  35.    
  36.     bcf PORTB, 0        ; Clear green light
  37.  
  38.     movlw   3           ;
  39.     movwf   tn          ; Set up for 3 second delay
  40.    
  41.     bsf PORTB, 1        ; Set amber light
  42.     call    delay_one       ; Delay one second
  43.    
  44.     bcf PORTB, 1        ; Clear amber light
  45.     call    delay_one       ; Delay one second
  46.    
  47.     decfsz  tn, f           ; Decrement tn
  48.     goto    $-5         ; Go back and repeat if tn isn't 0
  49.    
  50.     bsf PORTB, 2        ; Set red light
  51.    
  52.     movlw   5           ;
  53.     movwf   tn          ; Delay 5 seconds
  54.     call    delay_n         ;
  55.     bcf PORTB, 3        ; Clear red light
  56.    
  57.     goto    loop
  58.    
  59. ; Move n into tn before calling!
  60. delay_n:
  61.     decfsz  tn, f           ; Decrement until tn is zero
  62.     goto    $+2         ; If it's not zero, jump ahead to delay by a second
  63.    
  64.     return              ; Otherwise the job is done
  65.    
  66.     call delay_one          ; Delay for a second
  67.     goto delay_n            ; And return until it doesn't need to delay any more seconds
  68.  
  69. delay_one:
  70.     movlw   0x8A            ;
  71.     movwf   t1          ;
  72.     movlw   0xBA            ;
  73.     movwf   t2          ; I'll admit I cheated to find the best values for these
  74.     movlw   0x03            ;
  75.     movwf   t3          ;
  76.  
  77. delay_one_cycle:
  78.     decfsz  t1, f           ; 1 cycle except if zero
  79.     goto    $+2         ; 4 cycles
  80.     decfsz  t2, f
  81.     goto    $+2
  82.     decfsz  t3, f
  83.     goto    delay_one_cycle
  84.    
  85.     nop             ; 1 cycle
  86.    
  87.     return              ; 4 cycles including call
  88.    
  89.     end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top