assembly code help

Discussion in 'Homework Help' started by emaney, Jun 16, 2007.

  1. emaney

    Thread Starter New Member

    Jun 16, 2007
    1
    0
    The following code does this
    ;pic16f84a 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 TO FIX THIS..............PLEASE


    #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'
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    You are setting PORTA as input and PORTB as output. It should be the other way around.
     
Loading...