title "First Application - Light an LED and Poll a Button." ; ; This Code Simply Lights an LED and polls a button and turns ; on another LED when it is pressed. ; ; ; Hardware Notes: ; Reset is tied directly to Vcc and PWRT is Enabled. ; The PIC is a 16F84 Running at any speed. ; PortB.0 is Connected to a Button that pulls down to Ground when Pressed ; PortB.1 is Connected to an LED which is Pulled to Ground ("On" LED) ; PortB.2 is Connected to an LED which is Pulled to Ground ("Button" LED) ; ; Myke Predko ; 99.05.18 ; LIST P=16F84, R=DEC errorlevel 0,-305 INCLUDE "p16f84.inc" ; Register Usage CBLOCK 0x00C ; Start Registers at End of the Values ENDC PAGE __CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF ; Note that the WatchDog Timer is OFF ; First Application - Turn on LED and poll the Button. org 0 movlw 0x0FD ; Turn on LED on RB1 When Output Enabled movwf PORTB bsf STATUS, RP0 bcf TRISB ^ 0x080, 1 ; Enable RB1 for Output bcf TRISB ^ 0x080, 2 ; Enable RB2 for Output movlw 0x07F ; Enable Internal Pull-Ups movwf OPTION_REG ^ 0x080 bcf STATUS, RP0 Loop btfsc PORTB, 0 ; Is the Button Pressed? goto ButtonUp ; No, Light Off bcf PORTB, 2 ; Turn Light On goto Loop ButtonUp ; Button Up, Turn Light Off bsf PORTB, 2 goto Loop end