Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=16f627
- include "p16f627.inc"
- errorlevel -302
- __CONFIG 0x3D18
- movlw 0x07
- movwf CMCON
- banksel TRISA
- movlw 0xFF
- movwf TRISA
- clrf TRISB
- banksel PORTA
- t1 equ 0x20
- t2 equ 0x21
- t3 equ 0x22
- tn equ 0x23
- main:
- clrf PORTB
- loop:
- bsf PORTB, 0 ; Set green light
- btfss PORTA, 0 ; Check if switch is pressed
- goto loop ; Switch isn't pressed so stay green
- movlw 3 ;
- movwf tn ; Delay 3 seconds
- call delay_n ;
- bcf PORTB, 0 ; Clear green light
- movlw 3 ;
- movwf tn ; Set up for 3 second delay
- bsf PORTB, 1 ; Set amber light
- call delay_one ; Delay one second
- bcf PORTB, 1 ; Clear amber light
- call delay_one ; Delay one second
- decfsz tn, f ; Decrement tn
- goto $-5 ; Go back and repeat if tn isn't 0
- bsf PORTB, 2 ; Set red light
- movlw 5 ;
- movwf tn ; Delay 5 seconds
- call delay_n ;
- bcf PORTB, 3 ; Clear red light
- goto loop
- ; Move n into tn before calling!
- delay_n:
- decfsz tn, f ; Decrement until tn is zero
- goto $+2 ; If it's not zero, jump ahead to delay by a second
- return ; Otherwise the job is done
- call delay_one ; Delay for a second
- goto delay_n ; And return until it doesn't need to delay any more seconds
- delay_one:
- movlw 0x8A ;
- movwf t1 ;
- movlw 0xBA ;
- movwf t2 ; I'll admit I cheated to find the best values for these
- movlw 0x03 ;
- movwf t3 ;
- delay_one_cycle:
- decfsz t1, f ; 1 cycle except if zero
- goto $+2 ; 4 cycles
- decfsz t2, f
- goto $+2
- decfsz t3, f
- goto delay_one_cycle
- nop ; 1 cycle
- return ; 4 cycles including call
- end
Add Comment
Please, Sign In to add comment