tomas
Member level 1
- Joined
- Dec 16, 2012
- Messages
- 41
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,553
I have wrote assembler code in MPLAB, which controls light diodes connected to RB0, RB1, RB2 and RB3 with switches. Switches connected to RB4, RB5, RB6 and RB7.
Here's the code: (working)
Problem:
I need that 2 PIC's would be connected via USART. On 1 Pic (transmmiter) should be 4 switches and they could control 4 leds connected to second PIC.
1 PIC: RB0, RB1, RB2, RB3 - switches
2 Pic: RB0, RB1, RB2, RB3 - LEDS
Can anyone help me with code? How to change it?
Or maybe someone already has this code in assembler? Please help
Im using two PIC16f877's.
Here's the code: (working)
Code:
list P = 16F877
#INCLUDE <p16f877.inc>
; -------------------------------------------------------------
#Define Switch1 PORTB,4
#Define Switch2 PORTB,5
#Define Switch3 PORTB,6
#Define Switch4 PORTB,7
#Define Output1 PORTB,0
#Define Output2 PORTB,1
#Define Output3 PORTB,2
#Define Output4 PORTB,3
org 0x0000
;##########################################################################
Start
bsf STATUS,5
movlw b'11110000' ;4 inputs 4 outputs
movwf TRISB ;RB outputs
bcf STATUS,5
clrf PORTB
MainLoop
btfsc Switch1
goto Switch_1_Is_0
bcf Output1 ;set "0" RB0
goto Check_Switch_2
Switch_1_Is_0
bsf Output1 ;set "1" RB0
Check_Switch_2
btfsc Switch2
goto Switch_2_Is_0
bcf Output2
goto Check_Switch_3
Switch_2_Is_0
bsf Output2
Check_Switch_3
btfsc Switch3
goto Switch_3_Is_0
bcf Output3
goto Check_Switch_4
Switch_3_Is_0
bsf Output3
Check_Switch_4
btfsc Switch4
goto Switch_4_Is_0
bcf Output4
goto MainLoop
Switch_4_Is_0
bsf Output4
goto MainLoop
end ; end of program
Problem:
I need that 2 PIC's would be connected via USART. On 1 Pic (transmmiter) should be 4 switches and they could control 4 leds connected to second PIC.
1 PIC: RB0, RB1, RB2, RB3 - switches
2 Pic: RB0, RB1, RB2, RB3 - LEDS
Can anyone help me with code? How to change it?
Or maybe someone already has this code in assembler? Please help
Im using two PIC16f877's.