;*************************************************************** ;Dbt_sw2led ;Moves state of front microswitches to diagnostic leds ;If both switches on then buzzer goes on. ;TJW 24.3.05, rev. 1.4.09 Tested & working 20.8.05 ;*************************************************************** ;Clock is 4MHz ; list p=16F873a include p16f873a.inc ;Set Configuration Word: crystal oscillator HS, WDT off, ; power-up timer on, code protect off, LV Program off. __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF ;Specify RAM labels delcntr1 equ 20 ;used in delay SR delcntr2 equ 21 ; org 00 ;Initialise start bsf status,5 ;select memory bank 1 movlw B'00000000' ;all port A bits op movwf trisa movlw B'00110000' ;microswitches on bits 5 and 4 are only inputs movwf trisb ;port B bits movlw B'10000000' ;mode switch on bit 7 is only input movwf trisc ;port C bits movlw B'00000110' movwf adcon1 ;set port A for digital function bcf status,5 ;select bank 0 ; ;The “main” program starts here ;Switch all outputs off clrf porta clrf portb clrf portc ;diagnostic, switch leds on for half a second bsf portc,6 bsf portc,5 call delay500 bcf portc,6 bcf portc,5 call delay500 ;move microswitch states to leds. LED is OFF when switch pressed loop bcf portc,6 ;preclear port C, bit 6 (rt led off) btfsc portb,4 ;jump if right switch pressed bsf portc,6 ;led on if switch not pressed ; bcf portc,5 ;preclear port C, bit 5 (left led off) btfsc portb,5 ;jump if left switch pressed bsf portc,5 ;led on if switch not pressed ; btfsc portb,4 goto loop1 btfsc portb,5 goto loop1 bsf portb,1 ;switch on sounder if both pressed goto loop ;sounder stays on until one switch released loop1 bcf portb,1 ;switch off sounder goto loop ;********************************************** ;SUBROUTINES ;********************************************** ;introduces delay of 1ms approx delay1 movlw D'250' ;250 cycles called, ;each taking 4us movwf delcntr1 del1 nop ;4 inst cycles in this loop, ie 4us decfsz delcntr1,1 goto del1 return ; ;500ms delay (approx) ;500 calls to delay1 delay500 movlw D'250' movwf delcntr2 del5 call delay1 call delay1 decfsz delcntr2,1 goto del5 return end