;************************************************************* ;Flashing LEDs 2. ;This program continuously outputs a series of led patterns, ;using ping-pong hardware. LED patterns are derived using ;logical instructions. These are placed in different ;subroutines, of which one should be chosen. ;TJW 9.11.08 Tested in simulation 9.11.08 ;************************************************************* ;Clock is 800kHz ;Configuration Word: WDT off, power-up timer on, ; code protect off, RC oscillator ; list p=16F84A ; ;specify SFRs and bits c equ 0 pcl equ 02 status equ 03 trisa equ 05 portb equ 06 trisb equ 06 ; delcntr1 equ 11 ;used as counter in delay subroutine delcntr2 equ 12 ;used as counter in delay subroutine flags equ 13 ;bit 0 will be set once initial pattern is op ; org 00 ;Initialise start bsf status,5 ;select memory bank 1 movlw B'00011000' ;set port A right for hardware, movwf trisa ;even tho not used in this program. movlw 00 movwf trisb ;all port B bits output bcf status,5 ;select bank 0 clrf flags ; ;The “main” program starts here ;insert below one of pattern_XOR, pattern_RRF, pattern_IOR to be the ;target of this subroutine call loop call pattern_RRF ;select SR to be called here call delay goto loop ; ;************************************************************* ;Subroutines ;************************************************************* ;Changes led pattern, using XOR instruction pattern_XOR btfsc flags, 0 goto patt_XOR1 ;here if first visit to SR bsf flags,0 movlw B'10101010' movwf portb ;set up initial output pattern return patt_XOR1 movf portb,0 ;here if 2nd or later visit to SR xorlw B'11111111' movwf portb return ;Changes led pattern, using rrf instruction pattern_RRF btfsc flags, 0 goto patt_RRF1 ;here if first visit to SR bsf flags,0 movlw B'10000000' movwf portb ;set up initial output pattern return ;here if 2nd or later visit to SR patt_RRF1 bcf status,c ;clear carry flag rrf portb,1 btfsc status,c ;has pattern reached carry flag? bsf portb,7 ;if yes, reset msb return ;Changes led pattern, using OR and rrf instructions pattern_IOR btfsc flags, 0 goto patt_IOR1 ;here if first visit to SR bsf flags,0 clrf portb ;set up initial output pattern return patt_IOR1 rrf portb,0 ;here if 2nd or later visit to SR iorlw B'10000000';add another 1 bit to pattern btfsc status,c ;has pattern reached carry flag? clrw ;if yes, clear W movwf portb return ;Introduces delay of 500ms approx, for 800kHz clock delay movlw D'100' movwf delcntr2 outer movlw D'200' movwf delcntr1 inner nop nop decfsz delcntr1,1 goto inner decfsz delcntr2,1 goto outer return ; end