lebohangmaphothoane
Member
Hello guys Iam testing a button, This is how I want my project to work. When a button is pushed or pressed the three LEDs must be on.But when I push the button the LEDS do not light. can any one help me. On the attachment I have the design (proteus design) and the hex file. the code for my project is shown below
Code:
list p=16f877 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7E ; variable used for context saving
status_temp EQU 0x7F ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto Main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
Init
clrw ; Zero.
movwf PORTB ; resets input/output ports
bsf STATUS,RP0 ; Select Bank 1
movlw b'00000000' ; Set port B bits as outputs
movwf TRISB ; Set TRISB register.
bcf STATUS,RP0 ; Select Bank 0
retlw 0
Main
call Init
button_pressed
btfss PORTA,0 ;check whether button is pressed
goto button_pressed ; if not pressed keep checking or looping
goto loop ; if pressed then turn on the LEDs
loop
bsf PORTB,0 ;turn on the red light
bsf PORTB,1 ;turn on the yellow light
bsf PORTB,2 ;turn on the green light
goto loop
end