Friends I am struggling with this project : There is two switches, one at RB0, and the other at RB1; Two LED's that are sourcing current at RB4 and RB6; Two that are sinking current at RB5 and RB6... When the switch at RBO is pressed, the LED at RB4 must be on and the one atRB6 off. When the switch is released, LED at RB4 must be off and RB5 on... Same thing must also apply in switch 2, RB6 and RB7... Please help. I did it and it switches all led's when I press either switch 1 or 2.
HERE IS MY CODE>>>
Pleasse anyone.
HERE IS MY CODE>>>
Code:
LIST P = PIC16F627A
INCLUDE C:\Program Files (x86)\Microchip\MPASM Suite\p16f627a.inc
org 00
goto MAIN
FIRST_LED_ON:
bsf 6,4 ; turn port b pin 4 led on
goto switch2 ; goto next instructions
FIRST_LED_OFF:
bcf 6,4 ; turn port b pin 4 led off
goto switch2 ; goto next instructions
SECOND_LED_ON:
bsf 6,6 ; turn port b pin 6 led on
goto switch2 ; goto next instructions
SECOND_LED_OFF:
bcf 6,6 ; turn port b pin 6 led off
goto switch1 ; goto next instructions
THIRD_LED_ON:
bsf 6,5 ; turn port b pin 6 led on
goto switch2 ; goto next instructions
THIRD_LED_OFF:
bcf 6,5 ; turn port b pin 6 led off
goto switch2 ; goto next instructions
FOURTH_LED_ON:
bsf 6,7 ; turn port b pin 7 led on
goto switch1 ; goto next instructions
FOURTH_LED_OFF:
bcf 6,7 ; turn port b pin 7 led off
goto switch1 ; goto next instructions
MAIN:
movlw 0x07 ;load 7
movwf CMCON ;disable comparator
bsf 3,5 ;goto to bank 1 to configure the ports behaviour
bcf 5,0 ;make pin 0 in port A output
movlw b'00110000' ;make pin 0-1 outputs and pin 4-5 inputs
movwf 6 ;in portb
bcf 3,5 ;go back to bank 0
bsf 5,0 ;make pin 0 in port A on,to indicate that pic is on
switch1: ;switch connected to portb pin 0
btfss 6,0 ;check if switch is pressed
goto FIRST_LED_OFF ;turn off led when is not pressed
goto FIRST_LED_ON ;turn led on when is pressed
goto THIRD_LED_OFF ;turn led off at pin 5
goto THIRD_LED_ON ;turn led at pin 5 on when released
switch2: ;switch connected to portb pin 1
btfss 6,1 ;check if switch is pressed
goto SECOND_LED_OFF ;turn off led at pin 6 when not pressed
goto SECOND_LED_ON ;turn led at pin 6 on when is pressed
goto FOURTH_LED_OFF ;turn led off at pin 7
goto FOURTH_LED_ON ;turn led at pin 7 on when released
end
Pleasse anyone.
Last edited by a moderator: