title "ledon - Turn on a LED when a Button is Pressed"
include "D:/p16F877.inc"
__config (_CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_ON & _BODEN_ON & _LVP_OFF & _DEBUG_ON)
errorlevel -302
;;;;;;;;Vectors ;;
org H'000'
goto MainLine
org H'004'
goto IntService
Stop
goto Stop
;;;Interrupt Service;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IntService
retfie
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;; Initial Subroutine;;;;
Initial
bcf STATUS,RP0 ;
bcf STATUS, RP1 ; Bank 0 selected
clrf PORTC
clrf PORTB
bsf STATUS,RP0 ; Bank 1 selected
movlw H'00' ; All pins of PORTC outputs
movwf TRISC
movlw H'11'
movwf TRISB ; All pins of PORTB inputs
bcf STATUS,RP0 ; Bank 0 selected
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MainLine
call Initial
MainLoop
btfsc PORTB,0 ; check Button 1, if it is not pushed, skip the next step
goto B1_routine
btfsc PORTB,1 ; check Button 2, if it is not pushed, skip the next step
goto B2_routine
goto TurnOff ; if bit 0 is 1, goto Turnoff
B1_routine
movlw b'10101010'
movwf PORTC
goto MainLoop
B2_routine
movlw b'01010101'
movwf PORTC
goto MainLoop
TurnOff
clrf PORTC
goto MainLoop
end