The following code does this
;question
;A de-multiplexer has an input line, pinRB0, and four output
;lines, output0 to output3, which are, respectively, the pins RA0-RA3. the
;demultiplexer copies the digital signal appearing on the input line on to one of
;the four output lines. The output line is selected by a two bit
;selection code input on the pins RB1 and RB2.
PLEASE LOOK AT THE CODE BECAUSE ITS NOT EXACTLY DOING WHA IT IS MENTIONED ABOVE ANYONE CAN HELP ME FIX THIS..............PLEASE
Code:
#DEFINE PAGE0 BCF 0x03,5
#DEFINE PAGE1 BSF 0x03,5
PCL: EQU 0x02
STATUS: EQU 0x03
PORTA: EQU 0x05
TRISA: EQU 0x05
PORTB: EQU 0x06
TRISB: EQU 0x06
W: EQU 0
F: EQU 1
ORG 0x0
goto MAIN
org 5
MAIN:
clrf PORTA
clrf PORTNB
PAGE1
movlw B'00000111'
iorwf TRISA,F ;RA0-RA2 as input
clrf TRISB ;Port B0-B7 as output
PAGE0
loop:
;get the output selector
movf PORTB,w
rrf WREG
andlw B'00000011'
;convert 0-3 to bit-mask
call table
movwf Mask
;switch all zeroes to ones in mask and vice versa
xorlw B'11111111',w
;read all the bits of PORTA but the selected one (leave it clear)
andwf PORTA,w
;if PORTB.0 is set, set also selected output in PORTA
btfsc PORTB,0
xorwf Mask,w
;write modified value back to PORTA
movwf PORTA
goto loop
table:
addwf PCL,F
retlw B'00000001'
retlw B'00000010'
retlw B'00000100'
retlw B'00001000'